/
easy-waypoint-animate.js
67 lines (58 loc) · 2.49 KB
/
easy-waypoint-animate.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
var InitWaypointAnimations = (function () {
function onScrollInitAnimation(items, container, options) {
const containerOffset = ( container ) ? container.attr("data-animation-offset") || options.offset : null;
items.each( function() {
const element = $(this),
animationClass = element.attr("data-animation"),
animationDelay = element.attr("data-animation-delay") || options.delay,
animationOffset = element.attr("data-animation-offset") || options.offset;
element.css({
"-webkit-animation-delay": animationDelay,
"-moz-animation-delay": animationDelay,
"animation-delay": animationDelay,
"opacity": 0
});
const trigger = ( container ) ? container : element;
trigger.waypoint(function() {
element
.addClass("animated")
.addClass(animationClass)
.css({
"opacity": 1
});
},{
triggerOnce: true,
offset: containerOffset || animationOffset
});
});
}
function InitWaypointAnimations(defaults) {
if(!defaults) { defaults = {}; }
const options = {
offset: defaults.offset || "90%",
delay: defaults.delay || "0s",
animateClass: defaults.animateClass || "ez-animate",
animateGroupClass: defaults.animateGroupClass || "ez-animate-group"
}
const animateGroupClassSelector = classToSelector(options.animateGroupClass);
const animateClassSelector = classToSelector(options.animateClass);
// Attach waypoint animations to grouped animate elements
$(animateGroupClassSelector).each((index, group) => {
const container = $(group);
const items = $(group).find(animateClassSelector);
onScrollInitAnimation(items, container, options);
});
// Attach waypoint animations to ungrouped animate elements
$(animateClassSelector)
.filter((index, element) => {
return $(element).parents(animateGroupClassSelector).length === 0;
})
.each((index, element) => {
onScrollInitAnimation($(element), null, options);
});
}
function classToSelector(className) {
return "." + className;
}
return InitWaypointAnimations;
}());