Skip to content

Commit cb06db9

Browse files
committed
First working version
1 parent 79b1e36 commit cb06db9

File tree

4 files changed

+55
-19
lines changed

4 files changed

+55
-19
lines changed

package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
{
22
"name": "vue-animate-onscroll",
3-
"version": "0.0.3",
3+
"version": "0.0.4",
44
"description": "A simple component that animates element upon scroll",
55
"main": "src/index.js",
66
"author": "yev",
77
"repository": {
88
"type": "git",
99
"url": "https://github.com/josephharveyangeles/vue-animate-onscroll"
1010
},
11-
"keywords": ["vue", "scroll", "animate", "reveal"],
11+
"keywords": [
12+
"vue",
13+
"scroll",
14+
"animate",
15+
"reveal"
16+
],
1217
"license": "MIT",
13-
"dependencies": {
14-
"waypoints": "^4.0.1"
15-
}
18+
"dependencies": {}
1619
}

src/index.js

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,50 @@
1+
var ScrollAnimate = function(el, binding) {
2+
3+
var params = binding.value;
4+
var modifiers = binding.modifiers;
5+
var defaultClass = el.className;
6+
7+
function isInScrollView(rect){
8+
return rect.top < document.documentElement.clientHeight && rect.bottom > 0;
9+
}
10+
11+
return {
12+
dispatch: function(isUpwards) {
13+
if(!isInScrollView(el.getBoundingClientRect())) {
14+
if (modifiers.repeat) { // there will be a decision matrix for isUpwards and params.up or params.down
15+
// el.className = oldClasses;
16+
}
17+
return;
18+
}
19+
20+
var classToApply;
21+
if (typeof params === 'string') {
22+
classToApply = params;
23+
}
24+
else if (params.down && params.up) { // implicit repeat
25+
classToApply = isUpwards ? params.up : params.down;
26+
} else {
27+
classToApply = params.up || params.down;
28+
}
29+
el.className = defaultClass + ' ' + classToApply;
30+
}
31+
}
32+
}
33+
134
export default {
2-
install(Vue, options) {
3-
Vue.directive('vue-animate-onscroll', {
4-
});
35+
install(Vue, os = {}) {
36+
var scrollAnimate;
37+
Vue.directive('animate-onscroll', {
38+
bind(el, binding) {
39+
scrollAnimate = ScrollAnimate(el, binding);
40+
},
41+
inserted(el, binding) {
42+
window.addEventListener('scroll', function() {
43+
var isUpwards = this.oldScroll > this.scrollY;
44+
scrollAnimate.dispatch(isUpwards);
45+
this.oldScroll = this.scrollY;
46+
});
47+
}
48+
})
549
}
650
}

src/noframework.waypoints.min.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

yarn.lock

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,3 @@
22
# yarn lockfile v1
33

44

5-
waypoints@^4.0.1:
6-
version "4.0.1"
7-
resolved "https://registry.yarnpkg.com/waypoints/-/waypoints-4.0.1.tgz#09979a0573810b29627cba4366a284a062ec69c8"
8-
integrity sha1-CZeaBXOBCylifLpDZqKEoGLsacg=

0 commit comments

Comments
 (0)