-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (35 loc) · 1.46 KB
/
index.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
'use strict';
// ========================================navbar-toggle=======================================
const navopenBtn = document.querySelector("[data-nav-open-btn]");
const navbar= document.querySelector("[data-navbar]");
const navCloseBtn= document.querySelector("[data-nav-close-btn]");
const overlay= document.querySelector("[data-overlay]");
const elemArr = [navCloseBtn, overlay, navopenBtn];
for(let i =0; i < elemArr.length; i++){
elemArr[i].addEventListener("click", function() {
navbar.classList.toggle("active");
overlay.classList.toggle("active");
});
}
//=========================================== navlink toggle============================================
const navbarLinks = document.querySelectorAll("[data-navbar-link]");
for (let i=0; i < navbarLinks.length; 1++){
navbarLinks[1].addEventListener("click", function() {
navbar.classList.toggle("active");
overlay.classList.toggle("active");
});
}
//========================== header and go -top active when window scroll down to 400px================
const header = document.querySelector("[data-header]");
const goTopBtn = document.querySelector("[data-go-top]");
window.addEventListener("scroll", function(){
if(window.scrollY >= 400){
header.classList.add("active");
goTopBtn.classList.add("active");
}
else{
header.classList.remove("active");
goTopBtn.classList.remove("active");
}
}
);