-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
41 lines (32 loc) · 1 KB
/
Copy pathapp.js
File metadata and controls
41 lines (32 loc) · 1 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
39
40
41
const navBar = document.getElementById('navbar');
const barIcon = document.querySelector('.ham-menu')
const links = document.querySelector('#links')
function checkMediaQuery() {
// If the inner width of the window is greater then 768px
if (window.innerWidth > 768) {
// Then navBar is shown
navBar.style.display= 'block';
}else{
navBar.style.display= 'none';
}
}
// Add a listener for when the window resizes
window.addEventListener('resize', checkMediaQuery);
// Nav shown up after icon clicked
barIcon.addEventListener('click',showNav());
function showNav(){
if(navBar.style.display === 'block'){
navBar.style.display= 'none';
}else{
navBar.style.display= 'block';
}
}
// Nav hidden after items clicked
links.addEventListener('click',hideNav());
function hideNav(){
if(navBar.style.display === 'block' && window.innerWidth < 768){
navBar.style.display= 'none';
}else{
navBar.style.display= 'block';
}
}