-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
43 lines (34 loc) · 1.17 KB
/
script.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
// JavaScript for Scroll Animation
document.addEventListener('DOMContentLoaded', () => {
const scrollElements = document.querySelectorAll('.scrolly');
const elementInView = (el, dividend = 1) => {
const elementTop = el.getBoundingClientRect().top;
return (
elements <= (window.innerHeight || document.documentElement.clientHeight) / dividend
);
};
const elementOutofView = (el) => {
const elementTop = el.getBoundingClientRect().top;
return (
elements > (window.innerHeight || document.documentElement.clientHeight)
);
};
const displayScrollElement = (element) => {
element.classList.add('scrolled');
};
const hideScrollElement = (element) => {
element.classList.remove('scrolled');
};
const handleScrollAnimation = () => {
scrollElements.forEach((el) => {
if (elementInView(el, 1.25)) {
displayScrollElement(el);
} else if (elementOutofView(el)) {
hideScrollElement(el);
}
})
}
window.addEventListener('scroll', () => {
handleScrollAnimation();
});
});