-
Notifications
You must be signed in to change notification settings - Fork 2
/
ozmenu.js
40 lines (35 loc) · 1.45 KB
/
ozmenu.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
38
39
40
/*
* JavaScript - CSS Responsive Dropdown Menu
* Author : Oğuzhan Avcı
* https://github.com/oziavci
*/
const openMenu = document.querySelector(".menu-open");
const closeMenu = document.querySelector(".menu-close");
const menuDiv = document.querySelector(".ozmenu");
const menu = document.querySelector(".ozmenu-nav");
const dropDowns = menu.getElementsByClassName("nav-dropdown");
const dropDownsChild = menu.querySelectorAll('.dropdown .nav-dropdown');
openMenu.addEventListener("click", menuToggle);
closeMenu.addEventListener("click", menuToggle);
document.body.insertAdjacentHTML("beforeend", "<div id='menu-overlay'></div>");
document.querySelector("#menu-overlay").addEventListener("click", menuToggle);
function menuToggle() {
menuDiv.classList.toggle("active");
document.body.classList.toggle("hide-scrolling");
document.body.classList.toggle("mobile-menu-active");
document.getElementById("menu-overlay").classList.toggle("show");
}
for (var i = 0; i < dropDownsChild.length; i++) {
dropDownsChild[i].classList.add('child');
dropDownsChild[i].addEventListener("click", function() {
this.classList.toggle('opened');
});
}
for (var i = 0; i < dropDowns.length; i++) {
if(!dropDowns[i].classList.contains("child")){
dropDowns[i].classList.add('parent');
dropDowns[i].addEventListener("click", function() {
this.classList.toggle('opened');
});
}
}