-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
45 lines (39 loc) · 1.53 KB
/
script.js
File metadata and controls
45 lines (39 loc) · 1.53 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
42
43
44
45
// the background of the navbar should change when the page is scrolled.
window.addEventListener('scroll', function() {
const navbar = document.querySelector('.navbar-header');
const scrolled = window.scrollY > 0;
if (scrolled) {
navbar.classList.add('white-bg');
} else {
navbar.classList.remove('white-bg');
}
});
// //The background color of the navbar header should change when the menu is open.
// window.addEventListener('DOMContentLoaded', function() {
// const navbarToggle = document.querySelector('.navbar-toggle');
// const navbarHeader = document.querySelector('.navbar-header');
// navbarToggle.addEventListener('click', function() {
// if (navbarHeader.classList.contains('menu-open')) {
// navbarHeader.classList.remove('menu-open');
// } else {
// navbarHeader.classList.add('menu-open');
// }
// });
// });
window.addEventListener('DOMContentLoaded', function() {
const navbarToggle = document.querySelector('.navbar-toggle');
const navbarHeader = document.querySelector('.navbar-header');
navbarToggle.addEventListener('click', function() {
if (navbarHeader.classList.contains('menu-open')) {
navbarHeader.classList.remove('menu-open');
if (window.innerWidth < 600) {
navbarHeader.style.backgroundColor = 'transparent';
}
} else {
navbarHeader.classList.add('menu-open');
if (window.innerWidth < 600) {
navbarHeader.style.backgroundColor = '#f0f8ff';
}
}
});
});