-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
56 lines (49 loc) · 1.71 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
document.addEventListener("DOMContentLoaded", (event) => {
const menuToggle = document.getElementById("menu-toggle");
const closeMenu = document.getElementById("close-menu");
const mobileMenu = document.getElementById("mobile-menu");
const splineViewer = document.querySelector("spline-viewer");
const mobileGif = document.getElementById("mobile-gif");
function handleResize() {
if (window.innerWidth < 768) {
splineViewer.style.display = "none";
mobileGif.style.display = "block";
if (!mobileMenu.classList.contains("hidden")) {
mobileMenu.classList.add("hidden");
mobileMenu.classList.remove("flex");
}
} else {
splineViewer.style.display = "block";
mobileGif.style.display = "none";
mobileMenu.classList.add("hidden");
mobileMenu.classList.remove("flex");
}
}
handleResize();
window.addEventListener("resize", handleResize);
menuToggle.addEventListener("click", (e) => {
e.stopPropagation();
mobileMenu.classList.toggle("hidden");
mobileMenu.classList.toggle("flex");
});
closeMenu.addEventListener("click", () => {
mobileMenu.classList.add("hidden");
mobileMenu.classList.remove("flex");
});
document.addEventListener("click", (e) => {
if (!mobileMenu.contains(e.target) && e.target !== menuToggle) {
mobileMenu.classList.add("hidden");
mobileMenu.classList.remove("flex");
}
});
mobileMenu.addEventListener("click", (e) => {
e.stopPropagation();
});
const menuItems = mobileMenu.querySelectorAll("a");
menuItems.forEach((item) => {
item.addEventListener("click", () => {
mobileMenu.classList.add("hidden");
mobileMenu.classList.remove("flex");
});
});
});