-
Notifications
You must be signed in to change notification settings - Fork 754
/
navbar.js
37 lines (32 loc) · 887 Bytes
/
navbar.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
const navBar = document.getElementById("navbar");
const logo = document.getElementById("logo");
const navBtn = document.getElementById("nav-button");
let prevScrollPos = window.pageYOffset
navBtn.addEventListener("click", () => {
navBar.classList.toggle("hidden");
logo.classList.toggle("hidden");
});
window.onscroll = function() {
myFunction()
let currentScrollPos = window.pageYOffset
toggleNavBar(currentScrollPos > prevScrollPos, currentScrollPos)
};
var header = document.getElementById("header");
// var sticky = header.offsetTop;
function myFunction() {
if (window.pageYOffset > 10) {
header.classList.add("add_border");
}
else {
header.classList.remove("add_border");
}
}
function toggleNavBar(scrollDir, currPos){
prevScrollPos=currPos
if(scrollDir){
header.classList.add('nav-hidden')
}
else{
header.classList.remove('nav-hidden')
}
}