-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
40 lines (33 loc) · 1.37 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
document.getElementById("copyrightYear").innerHTML = new Date().getFullYear();
const toggleButton= document.getElementById('mobile-nav-toggle')
const nav= document.getElementById('navigation')
const mobile_menu= ()=>{
document.querySelectorAll('.nav[data-visible] a').forEach( a=> {
a.addEventListener('click', toggleNavigation);
})
}
// Function to toggle ARIA attribute and navigation visibility
function toggleNavigation() {
const expanded = toggleButton.getAttribute('aria-expanded') == 'true';
toggleButton.setAttribute('aria-expanded', !expanded);
nav.toggleAttribute('data-visible');
toggleButton.classList.toggle("menu-open");
mobile_menu()
}
toggleButton.addEventListener('click', toggleNavigation);
const contact_buttons = document.querySelectorAll('button[data-target="contact"]');
contact_buttons.forEach(button => {
button.addEventListener('click', () => {
document.getElementById('contact').scrollIntoView({ behavior: 'smooth' });
});
});
// add sticky header
window.addEventListener('scroll', () => {
const scrolledHeight = window.scrollY;
const header = document.getElementById('header');
if (scrolledHeight >= (0.15 * window.innerHeight)) { // 15% of the window height
header.classList.add('sticky-header', 'subtle-shadow');
} else {
header.classList.remove('sticky-header', 'subtle-shadow');
}
});