-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (31 loc) · 1 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
var counterContainer = document.querySelector(".website-counter");
var resetButton = document.querySelector("#reset");
var visitCount = localStorage.getItem("page_view");
var globalMediaQuery = window.matchMedia('(min-width:769px)');
// Check if page_view entry is present
if (visitCount) {
visitCount = Number(visitCount) + 1;
localStorage.setItem("page_view", visitCount);
} else {
visitCount = 1;
localStorage.setItem("page_view", 1);
}
counterContainer.innerHTML = visitCount;
// Adding onClick event listener
resetButton.addEventListener("click", () => {
visitCount = 1;
localStorage.setItem("page_view", 1);
counterContainer.innerHTML = visitCount;
});
function openNav() {
document.getElementById("navbar").style.width = "100%";
}
if(globalMediaQuery.matches){
document.getElementById("navbar").style.width = "100%";
}
function closeNav() {
let mediaQuery = window.matchMedia('(max-width: 768px)');
if(mediaQuery.matches) {
document.getElementById("navbar").style.width = "0";
}
}