Skip to content

Commit 1dd131b

Browse files
committed
use babel, eslint (airbnb), prettier, jest, etc.; umd & es6 dual version ; add banner; v0.1.0
1 parent 6c41806 commit 1dd131b

16 files changed

+6832
-2376
lines changed

.eslintrc.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
es6: true,
5+
},
6+
extends: [
7+
'airbnb-base',
8+
'prettier'
9+
],
10+
globals: {
11+
Atomics: 'readonly',
12+
SharedArrayBuffer: 'readonly',
13+
},
14+
parserOptions: {
15+
ecmaVersion: 2018,
16+
sourceType: 'module',
17+
},
18+
rules: {
19+
},
20+
};

.prettierrc.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
semi: true,
3+
singleQuote: true,
4+
trailingComma: "all",
5+
arrowParens: "always",
6+
printWidth: 100
7+
}

README.md

+29-30
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# wiscroll
22

3-
Scroll based animation JavaScript library. Vanilla js, 0 dependencies, ES6. Lightweight (around 1.6KB minified & gzipped). IntersectionObserver and scroll event based. Performance driven. Created recently due to frustration with IntersectionObserver and existing libraries. The library does not handle CSS, but examples with CSS will be put in the documentation. More documentation and demo are coming.
3+
Scroll based animation JavaScript library. Vanilla js, 0 dependencies. Lightweight: around 2.5KB transpiled ES5 (or 1.7KB ES6) minified & gzipped. IntersectionObserver based. Performance driven. The library does not handle CSS, but examples with CSS will be put in the documentation. More documentation and demo are coming.
44

55
<p align="center">
66
<img width="378.4" height="891.2" src="https://raw.githubusercontent.com/webisle/wiscroll/master/img/position-demo-gif/position-demo.gif">
@@ -17,12 +17,12 @@ import Wiscroll from 'wiscroll';
1717
## .on() : toggle class when one of target's borders passes one of root's borders/lines
1818
If target's top border passes root's 90% (from top) line, add class name "active" to the target, remove the class when scrolling back
1919
```javascript
20-
const target = document.querySelector(".wiscroll");
21-
new Wiscroll(target).on("90% top", "active");
20+
const target = document.querySelector('.wiscroll');
21+
new Wiscroll(target).on('90% top', 'active');
2222
```
2323
### Syntax
2424
<pre>
25-
.on("<i>rootBorderPosition</i> <i>targetBorderPosition</i>", "<i>classes</i>", <i>targetBorderIsHigher</i>)
25+
.on('<i>rootBorderPosition</i> <i>targetBorderPosition</i>', '<i>classes</i>', <i>targetBorderIsHigher</i>)
2626
</pre>
2727
* `rootBorderPosition`: specify a root border (or line), could be `top`, `bottom`, percentage number (e.g. `90%`), pixel number (e.g. `40px`), must be followed by `%` or `px` even if it's 0 (e.g. `0%`), positive number is position from top, negative number is position from bottom (e.g. `-10%` : 10% from bottom)
2828
* `targetBorderPosition`: specify a target border, could be `top`, `bottom`
@@ -32,18 +32,18 @@ new Wiscroll(target).on("90% top", "active");
3232
## .on() : do whatever you want when one of target's borders passes (or doesn't pass) one of root's borders/lines
3333
If target's top border is higher than root's 90% (from top) line, show "Target border is higher" in console, otherwise show "Target border is lower"
3434
```javascript
35-
new Wiscroll(target).on("90% top",
35+
new Wiscroll(target).on('90% top',
3636
function(entry) {
37-
console.log("Target border is higher");
37+
console.log('Target border is higher');
3838
},
3939
function(entry) {
40-
console.log("Target border is lower");
40+
console.log('Target border is lower');
4141
}
4242
);
4343
```
4444
### Syntax
4545
<pre>
46-
.on("<i>rootBorderPosition</i> <i>targetBorderPosition</i>", <i>functionWhenTargetHigher</i>, <i>functionWhenTargetLower</i>)
46+
.on('<i>rootBorderPosition</i> <i>targetBorderPosition</i>', <i>functionWhenTargetHigher</i>, <i>functionWhenTargetLower</i>)
4747
</pre>
4848
* `rootBorderPosition`: see above
4949
* `targetBorderPosition`: see above
@@ -54,31 +54,31 @@ new Wiscroll(target).on("90% top",
5454
When target's bottom border is touching (target is going into) root's 50% line, show "Target border is higher" in console
5555
```javascript
5656
new Wiscroll(target).on(
57-
"50% bottom in",
57+
'50% bottom in',
5858
function(entry) {
59-
console.log("Target border is passed");
59+
console.log('Target border is passed');
6060
}
6161
);
6262
```
6363
By the way, you might want to deal with initial states (when the page has just loaded and script has just been executed). Let's add a function to do something when my target border is higher (and lower) than my root's line
6464
```javascript
6565
new Wiscroll(target).on(
66-
"50% bottom in",
66+
'50% bottom in',
6767
function(entry) {
68-
console.log("Target border is passed");
68+
console.log('Target border is passed');
6969
},
7070
function(targetBIsHigher, entry) {
7171
if (targetBIsHigher) {
72-
console.log("Init: target border is higher");
72+
console.log('Init: target border is higher');
7373
} else {
74-
console.log("Init: target border is lower");
74+
console.log('Init: target border is lower');
7575
}
7676
}
7777
);
7878
```
7979
### Syntax
8080
<pre>
81-
.on("<i>rootBorderPosition</i> <i>targetBorderPosition</i> <i>motionDirection</i>", <i>function</i>, <i>initFunction</i>)
81+
.on('<i>rootBorderPosition</i> <i>targetBorderPosition</i> <i>motionDirection</i>', <i>function</i>, <i>initFunction</i>)
8282
</pre>
8383
* `rootBorderPosition`: see above
8484
* `targetBorderPosition`: see above
@@ -94,41 +94,41 @@ new Wiscroll(target).on(
9494
The `initFunction` mentioned above can be put into `.init()` method
9595
```javascript
9696
new Wiscroll(target).init(
97-
"50% bottom",
97+
'50% bottom',
9898
function(targetBIsHigher, entry) {
9999
if (targetBIsHigher) {
100-
console.log("Init: target border is higher");
100+
console.log('Init: target border is higher');
101101
} else {
102-
console.log("Init: target border is lower");
102+
console.log('Init: target border is lower');
103103
}
104104
}
105105
)
106106
.on( ... );
107107
```
108108
### Syntax
109109
<pre>
110-
.init("<i>rootBorderPosition</i> <i>targetBorderPosition</i>", <i>initFunction</i>)
110+
.init('<i>rootBorderPosition</i> <i>targetBorderPosition</i>', <i>initFunction</i>)
111111
</pre>
112112
However, it is recommanded you use initFunction in `.on()` instead of `.init()` to have fewer observers.
113113

114114
## .fromto() : change target dynamically depending on scroll position
115115
You can change the target progressively and continuously, or do whatever you want dynamically depending on target's scroll position (a percentage) between the two positions you have specified
116116
```javascript
117117
new Wiscroll(target).fromto(
118-
"-10% top",
119-
"20% bottom",
118+
'-10% top',
119+
'20% bottom',
120120
function(position, entry) { // position is from 0 to 1, could be < 0 or > 1 if out of boundary
121121
console.log(position);
122122
},
123123
{
124124
init: function(position, entry) {
125-
console.log("Init:" + position);
125+
console.log('Init:' + position);
126126
},
127127
in: function(position, entry) {
128-
console.log("In:" + position);
128+
console.log('In:' + position);
129129
},
130130
out: function(position, entry) {
131-
console.log("Out:" + position);
131+
console.log('Out:' + position);
132132
},
133133
delay: 150, // throttle delay
134134
fromIsBelowTo: true
@@ -138,8 +138,8 @@ new Wiscroll(target).fromto(
138138
### Syntax
139139
<pre>
140140
.fromto(
141-
"<i>rootBorderPositionFrom</i> <i>targetBorderPositionFrom</i>",
142-
"<i>rootBorderPositionTo</i> <i>targetBorderPositionTo</i>",
141+
'<i>rootBorderPositionFrom</i> <i>targetBorderPositionFrom</i>',
142+
'<i>rootBorderPositionTo</i> <i>targetBorderPositionTo</i>',
143143
<i>function</i>,
144144
<i>options</i>
145145
)
@@ -174,7 +174,7 @@ If you have basic knowledge of CSS and its [transition](https://developer.mozill
174174

175175
<details><summary><strong>Technical details</strong></summary>
176176

177-
[IntersectionObserver](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver) has better performance but there are lots of situation it can't handle, having a scroll event listener that only listens inside the specified area with some throttling added up there might be a good choice.
177+
[IntersectionObserver](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver) has good performance and can handle every scenario our method `.on()` deals with. Unfortunately, it can't handle some situations related to our `.fromto()` method, having a scroll event listener that only listens inside the specified area with some throttling added up there might be a good choice.
178178

179179
</details>
180180

@@ -187,7 +187,6 @@ If you have basic knowledge of CSS and its [transition](https://developer.mozill
187187
- [ ] see if this.target.getBoundingClientRect().top should be changed
188188
- [ ] other tests
189189
- [ ] test in Edge and mobile browsers
190-
- [ ] transpile the lib (or not)
191-
- [ ] I'll see what I can do to support IE11 but frankly I think we should just drop it.
190+
- [ ] I'll see what I can do to support IE11, will a simple polyfill of IntersectionObserver make it work? I'll try. But frankly I think we should just drop IE11.
192191

193-
</details>
192+
</details>

babel.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
"presets": [
3+
['@babel/preset-env'],
4+
]
5+
}

dist/index.es6.js

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)