-
Notifications
You must be signed in to change notification settings - Fork 1
/
bodymovin-animation.js
39 lines (35 loc) · 1.18 KB
/
bodymovin-animation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
function bodymovinAnimation() {
var scrollTop = $(document).scrollTop(),
windowHeight = $(window).height(),
indexList = [];
animations.each(function (index) {
var o = $(this);
if (o) {
var top = o.position().top;
if (scrollTop < top && scrollTop + windowHeight > top + (o.height() * 0.7)) {
var anim = bodymovin.loadAnimation({
container: this,
renderer: 'svg',
loop: false,
autoplay: true,
path: o.attr('src')
});
anim.onComplete = function (e) {
var animationEnd = this.wrapper.getAttribute("animation-end");
if (animationEnd) {
$(animationEnd).show("bounce");
}
}
indexList.push(index);
}
}
})
for (var i = indexList.length - 1; i >= 0; i--)
animations.splice(indexList[i], 1);
}
$(document).ready(function () {
// run
animations = $('.animation');
$(document).bind('scroll', bodymovinAnimation);
bodymovinAnimation();
});