-
Notifications
You must be signed in to change notification settings - Fork 0
/
mean.js
40 lines (34 loc) · 1.31 KB
/
mean.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
document.addEventListener('DOMContentLoaded', function() {
var header = document.getElementById('myHeader');
var page = document.getElementById('page');
var openMenuButton = document.getElementById('openmenu');
window.addEventListener('scroll', function() {
page.classList.remove('menuopen');
if (window.scrollY >= 100) {
header.classList.add('sticky');
} else {
header.classList.remove('sticky');
}
});
// Event listener to remove the sticky class when the button is clicked
openMenuButton.addEventListener('click', function() {
header.classList.remove('sticky');
page.classList.add('menuopen');
});
var links = document.querySelectorAll('a[href^="#"]');
links.forEach(function(link) {
link.addEventListener('click', function(event) {
// Prevent the default action
event.preventDefault();
// Get the target element
var targetId = this.getAttribute('href');
var targetElement = document.querySelector(targetId);
// Smooth scroll to target
if (targetElement) {
targetElement.scrollIntoView({
behavior: 'smooth'
});
}
});
});
});