Skip to content

Commit 4168763

Browse files
authored
Update script.js
1 parent 14ba8d3 commit 4168763

1 file changed

Lines changed: 29 additions & 11 deletions

File tree

public/script.js

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,47 @@ const rotasModais = {
2222
abrirModal: "modalContato"
2323
};
2424

25-
// ABRIR MODAIS
25+
// UX - MENU MOBILE (HAMBURGUER)
2626

27+
const menuToggle = document.getElementById("menuToggle");
28+
const navLinks = document.getElementById("navLinks");
2729

28-
Object.keys(rotasModais).forEach((idBotao) => {
30+
// ABRIR / FECHAR MENU
31+
if (menuToggle && navLinks) {
2932

30-
const elemento = document.getElementById(idBotao);
33+
menuToggle.addEventListener("click", function (e) {
34+
e.stopPropagation();
35+
navLinks.classList.toggle("active");
36+
});
3137

32-
if (!elemento) return;
38+
navLinks.addEventListener("click", function (e) {
39+
e.stopPropagation();
40+
});
3341

34-
elemento.addEventListener("click", function (e) {
42+
document.addEventListener("click", function () {
43+
navLinks.classList.remove("active");
44+
});
45+
}
3546

36-
e.preventDefault();
47+
// ABRIR MODAIS
3748

38-
const idModal = rotasModais[idBotao];
49+
Object.keys(rotasModais).forEach((idBotao) => {
3950

40-
const modal = document.getElementById(idModal);
51+
const elemento = document.getElementById(idBotao);
52+
const idModal = rotasModais[idBotao];
4153

42-
if (modal) {
54+
if (!elemento || !idModal) return;
4355

44-
modal.classList.add("ativo");
56+
const modal = document.getElementById(idModal);
4557

46-
}
58+
if (!modal) return;
59+
60+
elemento.addEventListener("click", function (e) {
61+
e.preventDefault();
62+
63+
navLinks?.classList.remove("active");
4764

65+
modal.classList.add("ativo");
4866
});
4967

5068
});

0 commit comments

Comments
 (0)