-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (26 loc) · 953 Bytes
/
index.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
const scrollAnimateEls = document.querySelectorAll(".scroll-animate");
const scrollTranslateEls = document.querySelectorAll(".scroll-translate");
init();
function init() {
const images=["./assets/background_3.jpg","./assets/background_2.png"]
window.addEventListener("scroll", triggerScrollAnimation, { passive: true });
preload(images, () => {
document.querySelector("body").classList.add("loaded");
});
}
function preload(images, callback) {
for (var i = 0; i < images.length; i++) {
var img=new Image();
img.src=images[i];
img.onload = callback;
}
}
function triggerScrollAnimation(){
scrollAnimateEls.forEach(el => {
if(el.classList.contains("animate")) return;
const rect = el.getBoundingClientRect();
const isInView = rect.top < window.innerHeight &&
rect.bottom >= 0;
if(isInView) el.classList.add("animate")
});
}