forked from PranavBarthwal/cosmoXplore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sidebar.js
32 lines (25 loc) · 930 Bytes
/
sidebar.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
function sidebarLogic() {
let menu = document.querySelector(".sidebar-menu");
let icon = document.querySelector(".sidebar-icon");
function toggleMenu() {
menu.classList.toggle("active");
}
icon.addEventListener("click", toggleMenu);
let sidebarItems = document.querySelectorAll(".sidebar-menu .rem");
sidebarItems.forEach(function(item) {
item.addEventListener("click", function() {
menu.classList.remove("active");
});
});
var prevScrollpos = window.pageYOffset;
window.onscroll = function() {
var currentScrollPos = window.pageYOffset;
if (prevScrollpos < currentScrollPos) {
document.querySelector(".sidebar-menu").classList.remove("active");
} else {
document.querySelector(".sidebar-menu").classList.remove("active");
}
prevScrollpos = currentScrollPos;
}
}
export default sidebarLogic;