-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
67 lines (52 loc) · 2.06 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
document.addEventListener('DOMContentLoaded', function() {
const hamburgerBtn = document.getElementById('hamburger-btn');
const mobileMenu = document.getElementById('mobile-menu');
const dropdowns = document.querySelectorAll('.dropdown');
// Toggle mobile menu visibility
hamburgerBtn.addEventListener('click', function() {
mobileMenu.classList.toggle('show');
});
// Toggle dropdowns
dropdowns.forEach(dropdown => {
dropdown.addEventListener('click', function(event) {
// Prevent the menu from closing immediately
event.stopPropagation();
// Close other open dropdowns
dropdowns.forEach(drop => {
if (drop !== dropdown) drop.querySelector('.dropdown-content').classList.remove('show');
});
// Toggle the current dropdown
const dropdownContent = this.querySelector('.dropdown-content');
dropdownContent.classList.toggle('show');
});
});
// Close dropdowns when clicking outside
document.addEventListener('click', function() {
dropdowns.forEach(dropdown => {
dropdown.querySelector('.dropdown-content').classList.remove('show');
});
});
});
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
var topBtn = document.getElementById("topBtn");
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
topBtn.style.display = "block";
} else {
topBtn.style.display = "none";
}
}
// When the user clicks on the button, scroll to the top of the document
function topFunction() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
window.onscroll = function() {scrollFunction()};
document.addEventListener('scroll', function() {
var navbar = document.querySelector('.navbar');
if (window.scrollY > 50) { // Adjust this value as needed
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
});