-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
35 lines (29 loc) · 968 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
const menu = document.querySelector(".menu_body");
const menuBtn = document.querySelector(".menu_icon");
const body = document.body;
if (menu && menuBtn) {
menuBtn.addEventListener("click", () => {
menu.classList.toggle("active");
menuBtn.classList.toggle("active");
body.classList.toggle("lock");
});
menu.querySelectorAll(".menu_link").forEach((link) => {
link.addEventListener("click", () => {
menu.classList.remove("active");
menuBtn.classList.remove("active");
body.classList.remove("lock");
});
});
}
// =======================================================
const anchors = document.querySelectorAll('a[href*="#"]');
anchors.forEach((anchors) => {
anchors.addEventListener("click", (event) => {
event.preventDefault();
const blockID = anchors.getAttribute("href").substring(1);
document.getElementById(blockID).scrollIntoView({
behavior: "smooth",
block: "start",
});
});
});