-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
40 lines (29 loc) · 1.07 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
const header = document.querySelector('header');
const mobButton = document.querySelector('.mobile');
const nav = document.querySelector('nav ul');
const menuItems = document.querySelectorAll('nav ul li a');
const toggleMenu = () => {
nav.classList.toggle('responsive');
};
mobButton.addEventListener('click', toggleMenu);
nav.addEventListener('click', function (event) {
if (event.target.tagName === 'A') {
toggleMenu(); // Close the menu when clicking a menu item
}
});
const backToTopButton = document.querySelector('#backToTop');
const getToTop = () => {
document.body.scrollTop = 0; // For Safari
document.documentElement.scrollTop = 0; // Chrome, Firefox, and others
};
window.onscroll = function() {
scrollFunction();
};
const scrollFunction = () => {
if (document.body.scrollTop > 200 || document.documentElement.scrollTop > 200) {
backToTopButton.style.display = "block";
} else {
backToTopButton.style.display = "none";
}
};
backToTopButton.addEventListener('click', getToTop);