-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
44 lines (38 loc) · 1.54 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
function toggleNavbar() {
const dropdownContent = document.getElementById("dropdown-content");
const topNavbar = document.querySelector(".navbar");
if (!dropdownContent) {
console.error("dropdownContent element not found");
return;
}
if (!dropdownContent.classList.contains("visible")) {
// Show dropdown
fetch('hamburgonclick.html')
.then(response => response.text())
.then(data => {
dropdownContent.innerHTML = data + '<button class="cross-button">✕</button>';
dropdownContent.classList.add("visible");
const crossButton = document.querySelector(".cross-button");
crossButton.addEventListener("click", toggleNavbar);
// Ensure the transition starts after the content is loaded
requestAnimationFrame(() => {
dropdownContent.style.transform = "translateY(0)";
dropdownContent.style.opacity = "1";
});
})
.catch(error => console.error('Error loading the HTML file:', error));
} else {
// Hide dropdown
dropdownContent.style.transform = "translateY(-100%)";
dropdownContent.style.opacity = "0";
// Wait for the transition to end before clearing the content
setTimeout(() => {
dropdownContent.classList.remove("visible");
dropdownContent.innerHTML = ''; // Clear the content when hiding
}, 500); // Match the transition duration
}
}
document.addEventListener('DOMContentLoaded', () => {
const hamburger = document.querySelector(".hamburger");
hamburger.addEventListener("click", toggleNavbar);
});