This repository has been archived by the owner on Sep 22, 2024. It is now read-only.
forked from JW33D/prueba
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
43 lines (37 loc) · 1.63 KB
/
main.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
document.addEventListener("DOMContentLoaded", function () {
const spans = document.querySelectorAll(".greetings span");
function startAnimation() {
// Set initial animation delays
spans.forEach((span, index) => {
span.style.animationDuration = "5s"; // Reset duration to 5s
span.style.animationDelay = `${index * 0.2}s`; // Incremental delay
});
// Calculate total duration of the initial animation (13 elements * 0.2s each + extra 0.6s for some padding delay)
const totalDuration = spans.length * 0.2 + 0.6;
// Set a timeout for when to reset the animations
setTimeout(() => {
spans.forEach((span) => {
span.style.animationDuration = "4s"; // Change duration to 4s
span.style.animationDelay = "0s"; // Reset delay set to 0 to start immediately
});
// Set another timeout to revert back to original settings
setTimeout(() => {
spans.forEach((span) => {
// Remove the animation class to reset
span.style.animation = "none";
});
// Force reflow to restart the animation
void spans[0].offsetWidth; // Trigger reflow
spans.forEach((span, index) => {
span.style.animationDuration = "5s"; // Reset duration to the original 5s
span.style.animationDelay = `${index * 0.2}s`; // Reset delay
span.style.animation = ""; // Re-add animation property
});
// Start the animation again
startAnimation();
}, 3000); // Wait for 3s before resetting back
}, totalDuration * 1000); // Convert to milliseconds
}
// Start the first animation cycle
startAnimation();
});