-
Notifications
You must be signed in to change notification settings - Fork 0
/
aos.js
32 lines (32 loc) · 1.08 KB
/
aos.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
var eleAOS = document.getElementsByClassName("appear-on-scroll");
var repeat = true;
var vh = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
var elementOffset = vh / 6;
const getOffsetTop = function(element) {
let offsetTop = 0;
while (element) {
offsetTop += element.offsetTop;
element = element.offsetParent;
}
return offsetTop;
};
Array.from(eleAOS).forEach(function(element) {
if (
document.body.scrollTop + vh - elementOffset > getOffsetTop(element) ||
document.documentElement.scrollTop + vh - elementOffset > getOffsetTop(element)
) {
element.classList.add("force-appear");
}
});
window.onscroll = function() {
Array.from(eleAOS).forEach(function(element) {
if (
document.body.scrollTop + vh - elementOffset > getOffsetTop(element) ||
document.documentElement.scrollTop + vh - elementOffset > getOffsetTop(element)
) {
element.classList.add("appear");
} else if (repeat) {
element.classList.remove("appear");
}
});
};