-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
54 lines (47 loc) · 1.75 KB
/
script.js
File metadata and controls
54 lines (47 loc) · 1.75 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
46
47
48
49
50
51
52
53
54
// Selectors
const navItems = document.querySelectorAll('.nav-item');
const hamburger = document.querySelector('.hamburger');
const navLinks = document.querySelector('.nav-links');
// Toggle Navigation Links
hamburger.addEventListener('click', () => {
navLinks.classList.toggle('open');
hamburger.classList.toggle('open');
});
// Open/Close Dropdown
navItems.forEach(item => {
const dropdown = item.querySelector('.dropdown');
if (dropdown) {
item.addEventListener('mouseenter', () => {
dropdown.style.opacity = '1';
dropdown.style.visibility = 'visible';
dropdown.style.transform = 'translateY(0)';
});
item.addEventListener('mouseleave', () => {
dropdown.style.opacity = '0';
dropdown.style.visibility = 'hidden';
dropdown.style.transform = 'translateY(10px)';
});
item.addEventListener('click', () => {
const isOpen = dropdown.style.opacity === '1';
if (isOpen) {
dropdown.style.opacity = '0';
dropdown.style.visibility = 'hidden';
dropdown.style.transform = 'translateY(10px)';
} else {
dropdown.style.opacity = '1';
dropdown.style.visibility = 'visible';
dropdown.style.transform = 'translateY(0)';
}
});
}
});
// Smooth Scrolling for Anchor Links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth',
block: 'start'
});
});
});