forked from CSI-DMCE-2024/Ecommerce-Hacktoberfest2024
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
33 lines (28 loc) · 951 Bytes
/
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
let backToTopButton = document.getElementById("backToTop");
/*show the button after scrolling down 300 pixel*/
window.onscroll = function() {
if (document.body.scrollTop > 300 || document.documentElement.scrollTop > 300) {
backToTopButton.style.display = "block";
} else {
backToTopButton.style.display = "none";
}
};
/*smooth scrolling to the top when the button is clicked*/
backToTopButton.onclick = function() {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
};
function toggleMenu() {
const navbar = document.querySelector('.navbar');
navbar.classList.toggle('active'); // Toggle the active class
};
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});