-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
38 lines (32 loc) · 1003 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
31
32
33
34
35
36
37
38
document.addEventListener("DOMContentLoaded", (event) => {
const header = document.querySelector(".header-div");
const grids = document.querySelectorAll(".grid");
const pricingDivs = document.querySelectorAll("#pricing-div");
window.addEventListener("scroll", () => {
if (window.scrollY > 50) {
header.classList.add("scrolled");
} else {
header.classList.remove("scrolled");
}
grids.forEach((grid) => {
if (isElementInViewport(grid)) {
grid.classList.add("visible");
}
});
pricingDivs.forEach((div) => {
if (isElementInViewport(div)) {
div.classList.add("visible");
}
});
});
function isElementInViewport(el) {
const rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <=
(window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
}
});