-
Notifications
You must be signed in to change notification settings - Fork 6
/
script.js
30 lines (26 loc) · 892 Bytes
/
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
document.addEventListener("DOMContentLoaded", function() {
const animatedElement = document.getElementById("animatedElement");
const section = document.querySelector(".section");
let isInViewport = false;
function checkVisibility() {
const rect = section.getBoundingClientRect();
isInViewport = rect.top <= window.innerHeight && rect.bottom >= 0;
}
function animateElement() {
if (isInViewport) {
animatedElement.style.opacity = "1";
animatedElement.style.transform = "translate(-50%, -50%) scale(1)";
} else {
animatedElement.style.opacity = "0";
animatedElement.style.transform = "translate(-50%, -50%) scale(0)";
}
}
// Check visibility on page load
checkVisibility();
animateElement();
// Listen for scroll events
window.addEventListener("scroll", function() {
checkVisibility();
animateElement();
});
});