-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
62 lines (49 loc) · 2.3 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
let lastScrollPosition = 0;
window.addEventListener("scroll", function () {
const desktopNavbar = document.querySelector(".desktop nav");
const mobileNavbar = document.querySelector(".mobile nav");
const currentScrollPosition = window.scrollY;
if (currentScrollPosition === 0) {
desktopNavbar.style.transform = "translateY(85px)"; // Push the desktop navbar down 60px when at the top of the page
mobileNavbar.style.transform = "translateY(85px)"; // Push the mobile navbar down 60px when at the top of the page
} else if (currentScrollPosition > lastScrollPosition) {
desktopNavbar.style.transform = "translateY(-100%)"; // Move the desktop navbar outside the page when scrolling down
mobileNavbar.style.transform = "translateY(-100%)"; // Move the mobile navbar outside the page when scrolling down
} else {
desktopNavbar.style.transform = "translateY(0)"; // Move the desktop navbar to the top of the page when scrolling up
mobileNavbar.style.transform = "translateY(0)"; // Move the mobile navbar to the top of the page when scrolling up
}
lastScrollPosition = currentScrollPosition;
});
// Mobile menu
document.querySelector(".burgerMenu").addEventListener("click", function () {
document.querySelector(".mobileToggled").classList.remove("hide");
});
document.querySelector(".close").addEventListener("click", function () {
document.querySelector(".mobileToggled").classList.add("hide");
});
// Desktop menu
document.querySelectorAll(".menuButton").forEach(function (menuButton) {
menuButton.addEventListener("click", function () {
document.querySelector(".desktopToggled").classList.remove("hide");
});
});
// Add hide when clicking outside the desktopToggled
document.addEventListener("click", function (event) {
const desktopToggled = document.querySelector(".desktopToggled");
const targetElement = event.target;
if (
!desktopToggled.contains(targetElement) &&
!targetElement.classList.contains("menuButton")
) {
desktopToggled.classList.add("hide");
}
});
document
.querySelector(".desktopCenter .close")
.addEventListener("click", function () {
document.querySelector(".desktopToggled").classList.add("hide");
});
document.querySelector(".logoDesktop").addEventListener("click", function () {
window.scrollTo({ top: 0, behavior: "smooth" });
});