-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrpit.js
34 lines (28 loc) · 947 Bytes
/
scrpit.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
const sections = document.querySelectorAll('.section');
const navItems = document.querySelectorAll('.nav-item');
let currentSection = 'home';
window.addEventListener('scroll', () => {
sections.forEach((sec) => {
if (window.scrollY >= sec.offsetTop - 50) {
currentSection = sec.id;
}
});
navItems.forEach((item) => {
if (item.href.includes(currentSection)) {
document.querySelector('.active').classList.remove('active');
item.classList.add('active');
}
});
});
const hamBtn = document.getElementById('ham-btn');
const navBar = document.querySelector('.nav-bar');
hamBtn.addEventListener('click', () => {
navBar.classList.toggle('nav-bar-visible');
});
window.addEventListener('resize', () => {
if (window.innerWidth > 768) {
navBar.classList.add('nav-bar-visible');
} else {
navBar.classList.remove('nav-bar-visible');
}
});