forked from cs-4241-2024/a1-gettingstarted
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
39 lines (34 loc) · 1.24 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
document.addEventListener("DOMContentLoaded", function() {
// animation for headers
const headers = document.querySelectorAll('h1, h2');
headers.forEach(header => {
let position = 0;
let direction = 1;
const amplitude = 2;
const speed = 0.2;
function bounce() {
position += direction * speed;
if (position >= amplitude || position <= 0) {
direction *= -1;
}
header.style.transform = `translateY(${position}px)`;
requestAnimationFrame(bounce);
}
bounce();
});
// dropdown toggle functionality
const buttons = document.querySelectorAll('.toggle-button');
buttons.forEach(button => {
const dropdownContent = button.nextElementSibling;
dropdownContent.style.display = "none"; // dropdown is hidden initially
button.addEventListener('click', function() {
if (dropdownContent.style.display === "none") {
dropdownContent.style.display = "block";
this.innerHTML = "▲";
} else {
dropdownContent.style.display = "none";
this.innerHTML = "▼";
}
});
});
});