Skip to content

Commit 5348588

Browse files
mobile menu js
1 parent 49eacb9 commit 5348588

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/js/mobilMenu.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
document.addEventListener('DOMContentLoaded', function () {
2+
const menu = document.querySelector('[data-mobile-navbar]');
3+
const closeBtn = document.querySelector('.navbar-button-close');
4+
const menuLinks = document.querySelectorAll(
5+
'.navbar-nav-link, .navbar-join-link-mobile, .join-now-button-bottom, .navbar-join-link-desktop'
6+
);
7+
8+
function closeMenu() {
9+
menu.classList.add('is-hidden');
10+
}
11+
12+
// Закрытие по кнопке
13+
closeBtn.addEventListener('click', closeMenu);
14+
15+
// Закрытие и переход по якорю
16+
menuLinks.forEach(link => {
17+
link.addEventListener('click', function (e) {
18+
e.preventDefault();
19+
20+
const targetId = this.getAttribute('href').replace('#', '');
21+
const target = document.getElementById(targetId);
22+
23+
// Закрытие меню
24+
closeMenu();
25+
26+
// Плавный скролл
27+
if (target) {
28+
setTimeout(() => {
29+
target.scrollIntoView({ behavior: 'smooth' });
30+
}, 300); // Ждём, пока меню скроется (если нужно)
31+
}
32+
});
33+
});
34+
});

0 commit comments

Comments
 (0)