-
Notifications
You must be signed in to change notification settings - Fork 0
/
x.js
51 lines (35 loc) · 1.16 KB
/
x.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
41
42
43
44
45
46
47
48
49
50
51
'use strict';
/**
* element toggle function
*/
const elemToggleFunc = function (elem) { elem.classList.toggle("active"); }
/**
* navbar toggle
*/
const navbar = document.querySelector("[data-navbar]");
const overlay = document.querySelector("[data-overlay]");
const navCloseBtn = document.querySelector("[data-nav-close-btn]");
const navOpenBtn = document.querySelector("[data-nav-open-btn]");
const navbarLinks = document.querySelectorAll("[data-nav-link]");
const navElemArr = [overlay, navCloseBtn, navOpenBtn];
/**
* close navbar when click on any navbar link
*/
for (let i = 0; i < navbarLinks.length; i++) { navElemArr.push(navbarLinks[i]); }
/**
* addd event on all elements for toggling navbar
*/
for (let i = 0; i < navElemArr.length; i++) {
navElemArr[i].addEventListener("click", function () {
elemToggleFunc(navbar);
elemToggleFunc(overlay);
});
}
/**
* header active state
*/
const header = document.querySelector("[data-header]");
window.addEventListener("scroll", function () {
window.scrollY >= 400 ? header.classList.add("active")
: header.classList.remove("active");
});