-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
48 lines (38 loc) · 1.23 KB
/
script.js
File metadata and controls
48 lines (38 loc) · 1.23 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
// ================== Modal ==================
document.addEventListener("DOMContentLoaded", () => {
const modal = document.getElementById("read");
const readMoreBtn = document.querySelector(".read-more-btn");
const closeBtn = document.querySelector(".modal-content .close");
if (modal && readMoreBtn && closeBtn) {
// open modal
readMoreBtn.addEventListener("click", () => {
modal.style.display = "flex";
});
//close modal
closeBtn.addEventListener("click", () => {
modal.style.display = "none";
});
// // close modal on outside click
window.addEventListener("click", (e) => {
if (e.target === modal) {
modal.style.display = "none";
}
});
}
});
// ================== Hamburger Menu ==================
document.addEventListener("DOMContentLoaded", () => {
const hamburger = document.getElementById("hamburger");
const navLinks = document.getElementById("navLinks");
if (hamburger && navLinks) {
hamburger.addEventListener("click", () => {
navLinks.classList.toggle("active");
});
}
//when click outside the menu -> menu should be close
document.addEventListener("click", (e) => {
if (!navLinks.contains(e.target) && !hamburger.contains(e.target)) {
navLinks.classList.remove("active");
}
})
});