-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
52 lines (30 loc) · 1.03 KB
/
script.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
52
'use strict';
/**
* navbar variables
*/
const navOpenBtn = document.querySelector("[data-menu-open-btn]");
const navCloseBtn = document.querySelector("[data-menu-close-btn]");
const navbar = document.querySelector("[data-navbar]");
const overlay = document.querySelector("[data-overlay]");
const navElemArr = [navOpenBtn, navCloseBtn, overlay];
for (let i = 0; i < navElemArr.length; i++) {
navElemArr[i].addEventListener("click", function () {
navbar.classList.toggle("active");
overlay.classList.toggle("active");
document.body.classList.toggle("active");
});
}
/**
* header sticky
*/
const header = document.querySelector("[data-header]");
window.addEventListener("scroll", function () {
window.scrollY >= 10 ? header.classList.add("active") : header.classList.remove("active");
});
/**
* go top
*/
const goTopBtn = document.querySelector("[data-go-top]");
window.addEventListener("scroll", function () {
window.scrollY >= 500 ? goTopBtn.classList.add("active") : goTopBtn.classList.remove("active");
});