-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnftc.js
47 lines (39 loc) · 1.28 KB
/
nftc.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
/**
* navbar toggle
*/
const overlay = document.querySelector("[data-overlay]"),
navbar = document.querySelector("[data-navbar]"),
menuCloseBtn = document.querySelector("[data-nav-close-btn]"),
menuOpenBtn = document.querySelector("[data-nav-open-btn]");
const elemArr = [overlay, menuCloseBtn, menuOpenBtn];
for (let i = 0; i < elemArr.length; i++) {
elemArr[i].addEventListener("click", function () {
navbar.classList.toggle("active");
overlay.classList.toggle("active");
});
}
/**
* toggle navbar when any navbar link will be clicked
*/
const navbarLinks = document.querySelectorAll("[data-navlink]");
for (let i = 0; i < navbarLinks.length; i++) {
navbarLinks[i].addEventListener("click", function () {
navbar.classList.toggle("active");
overlay.classList.toggle("active");
});
}
/**
* add active class on header and back-to-top btn
* when window will scroll 100px from top
*/
const header = document.querySelector("[data-header]");
const backTopBtn = document.querySelector("[data-back-top-btn]");
window.addEventListener("scroll", function () {
if (window.scrollY >= 100) {
header.classList.add("active");
backTopBtn.classList.add("active");
} else {
header.classList.remove("active");
backTopBtn.classList.remove("active");
}
});