Skip to content

Commit de4d26f

Browse files
committed
Bugfix: Repeat modifier not working on suceeding instance
- caused by improper scroll detection - simplified code, attached to inserted directly instead of using bind
1 parent 26d135b commit de4d26f

File tree

4 files changed

+9
-13
lines changed

4 files changed

+9
-13
lines changed

lib/vue-animate-onscroll.cjs.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/vue-animate-onscroll.es.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@ import ScrollAnimate from './scroll-animate'
33
export default {
44
ScrollAnimate,
55
install(Vue) {
6-
let scrollAnimate;
76
Vue.directive('animate-onscroll', {
8-
bind(el, binding) {
9-
scrollAnimate = ScrollAnimate()
10-
},
117
inserted(el, binding) {
8+
const scrollAnimate = ScrollAnimate(Date.now())
129
const previousClassName = el.className
10+
let lastScrollTop = window.pageYOffset
1311
window.addEventListener('scroll', function() {
14-
const isUpwards = this.oldScroll > this.scrollY
12+
let scrollTop = window.pageYOffset || document.documentElement.scrollTop
13+
const isUpwards = scrollTop < lastScrollTop
1514
scrollAnimate.run(el, binding, {isUpwards, previousClassName})
16-
this.oldScroll = this.scrollY
17-
})
15+
lastScrollTop = scrollTop <= 0 ? 0 : scrollTop
16+
}, false)
1817
}
1918
})
2019
}

src/scroll-animate.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default () => {
1313
const shouldResetAnimation = ({params, isUpwards, repeat}) => repeat &&
1414
(isUpwards && params.down || !isUpwards && params.up)
1515

16-
const applyAnimationClass = (el, current, newClass = '') => el.className = `${current} ${newClass}`
16+
const applyAnimationClass = (el, current, newClass = '') => el.className = `${current} ${newClass}`.trim()
1717

1818
return {
1919
isInView: isInScrollView,
@@ -45,6 +45,3 @@ export default () => {
4545
}
4646

4747
}
48-
49-
50-

0 commit comments

Comments
 (0)