-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
41 lines (34 loc) · 1.35 KB
/
script.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
39
40
41
document.addEventListener("DOMContentLoaded", () => {
const menuIcon = document.getElementById("menu-icon");
const sidebar = document.querySelector(".sidebar");
menuIcon.addEventListener("click", () => {
sidebar.classList.toggle("open");
});
const menuItems = document.querySelectorAll('.menu-item');
menuItems.forEach(item => {
item.addEventListener('click', function(e) {
e.preventDefault();
menuItems.forEach(menu => menu.classList.remove('active'));
this.classList.add('active');
const targetId = this.getAttribute('href').substring(1);
const targetSection = document.getElementById(targetId);
targetSection.scrollIntoView({ behavior: 'smooth' });
sidebar.classList.toggle("open");
});
});
const sections = document.querySelectorAll('section');
const options = {
threshold: 0.5
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
menuItems.forEach(menu => menu.classList.remove('active'));
document.querySelector(`a[href="#${entry.target.id}"]`).classList.add('active');
}
});
}, options);
sections.forEach(section => {
observer.observe(section);
});
});