forked from tecxick/TAnimations
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTAnimations.js
More file actions
28 lines (23 loc) · 788 Bytes
/
TAnimations.js
File metadata and controls
28 lines (23 loc) · 788 Bytes
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
let scroll_elements = [];
function scrolling() {
console.log("Scrolling");
scroll_elements.forEach(element => {
let in_anim = element.getAttribute("data-scroll");
let out_anim = in_anim.replace("in", "out");
let top = element.getBoundingClientRect().top;
let bottom = element.getBoundingClientRect().bottom;
if (top < window.innerHeight) {
if (element.className !== in_anim) {
element.className = in_anim;
}
}
if (bottom > window.innerHeight) {
element.className = out_anim;
}
});
}
function AnimInit() {
console.log("Initialized");
scroll_elements = document.querySelectorAll('[data-scroll]');
window.addEventListener("scroll", scrolling);
}