-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
37 lines (30 loc) · 1.03 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
const btnMobile = document.querySelector("#btn-mobile");
function toggleMenu(event) {
if (event.type === "touchstart") event.preventDefault();
const nav = document.getElementById("nav");
nav.classList.toggle("active");
const active = nav.classList.contains("active");
event.currentTarget.setAttribute("aria-expanded", active);
if (active) {
event.currentTarget.setAttribute("aria-label", "Fechar Menu");
} else {
event.currentTarget.setAttribute("aria-label", "Abrir Menu");
}
}
btnMobile.addEventListener("click", toggleMenu);
btnMobile.addEventListener("touchstart", toggleMenu);
/*SCROLL SUAVE*/
const linksInternos = document.querySelectorAll("#menu a[href^='#']");
function scrollToSection(event) {
event.preventDefault();
const href = event.currentTarget.getAttribute("href");
const section = document.querySelector(href);
const topo =section.offsetTop
window.scrollTo({
top:topo,
behavior:"smooth",
})
}
linksInternos.forEach((link) => {
link.addEventListener("click", scrollToSection);
});