-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
67 lines (57 loc) · 1.8 KB
/
Copy pathscript.js
File metadata and controls
67 lines (57 loc) · 1.8 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// For sticky navbar
document.addEventListener("DOMContentLoaded", function () {
const navbar = document.querySelector(".navbar");
const navbarHeight = navbar.offsetHeight;
let lastScrollY = 0;
window.addEventListener("scroll", function () {
if (window.scrollY > navbarHeight) {
if (window.scrollY > lastScrollY) {
navbar.style.transform = "translateY(-100%)";
} else {
navbar.style.transform = "translateY(0)";
navbar.style.position = "fixed";
navbar.style.top = "0";
navbar.style.width = "100%";
navbar.style.zIndex = "1000";
}
} else {
navbar.style.transform = "translateY(0)";
navbar.style.position = "relative";
}
lastScrollY = window.scrollY;
});
});
// about
document.addEventListener("DOMContentLoaded", function () {
const hiddenElements = document.querySelectorAll(".hidden");
function handleScrollAnimation(entries, observer) {
entries.forEach(function (entry) {
if (entry.isIntersecting) {
entry.target.classList.add("animate");
observer.unobserve(entry.target);
}
});
}
const observer = new IntersectionObserver(handleScrollAnimation, {
threshold: 0.1,
});
hiddenElements.forEach(function (element) {
observer.observe(element);
});
});
// special?
document.addEventListener("DOMContentLoaded", function () {
const specialOffersSection = document.querySelector(".special-offers");
function showSpecialOffers(entries, observer) {
entries.forEach(function (entry) {
if (entry.isIntersecting) {
specialOffersSection.classList.add("visible");
observer.unobserve(entry.target);
}
});
}
const observer = new IntersectionObserver(showSpecialOffers, {
threshold: 0.2,
});
observer.observe(specialOffersSection);
});