-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
executable file
·38 lines (33 loc) · 1.03 KB
/
script.js
File metadata and controls
executable file
·38 lines (33 loc) · 1.03 KB
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
// Show/Hide Nav on scroll
var prevScrollpos = window.pageYOffset;
window.onscroll = function() {
var currentScrollPos = window.pageYOffset;
if (prevScrollpos > currentScrollPos) {
document.getElementById("nav").style.top = "0";
} else {
document.getElementById("nav").style.top = "-165px";
}
prevScrollpos = currentScrollPos;
}
// Add class to nav on scroll
window.addEventListener("scroll", function(e) {
var nav = document.getElementById("nav");
if (
document.documentElement.scrollTop >= 50 ||
document.body.scrollTop > window.innerHeight
) {
nav.classList.add("nav-colored");
nav.classList.remove("nav-transparent");
} else {
nav.classList.add("nav-transparent");
nav.classList.remove("nav-colored");
}
});
// Hide mobile nav on link click
let getList = document.querySelectorAll(".navbar li a");
// convert NodeList to Array
let items = [...getList];
let tog = document.querySelector("#toggle");
items.map((item) => {
item.addEventListener('click', () => tog.checked = false);
});