Common.js : Différence entre versions
De erg
| Ligne 35 : | Ligne 35 : | ||
} | } | ||
| − | var animationInterval = setInterval(animate, | + | var animationInterval = setInterval(animate, 500); // Reset the animation every 5000 milliseconds |
} | } | ||
Version du 22 janvier 2024 à 17:16
console.log("it's tiiiiiime");
var snowflakes = ["❄", "❅", "☣","☠", "❆"];
function createSnowflake() {
var snowflake = document.createElement('div');
snowflake.className = 'snowflake';
snowflake.innerHTML = snowflakes[Math.floor(Math.random() * snowflakes.length)];
snowflake.style.left = Math.floor(Math.random() * (document.documentElement.clientWidth || document.body.clientWidth)) + 'px';
snowflake.style.top = '0';
document.body.appendChild(snowflake);
setTimeout(function () {
document.body.removeChild(snowflake);
}, 5000);
}
function animateSnowflakes() {
var snowflakes = document.getElementsByClassName('snowflake');
var iterationCount = 0;
function animate() {
for (var i = 0; i < snowflakes.length; i++) {
var snowflake = snowflakes[i];
snowflake.style.top = '0';
void snowflake.offsetWidth; // Trigger reflow
snowflake.style.top = '100vh'; // Set the end position
}
iterationCount++;
if (iterationCount >= 20) {
clearInterval(animationInterval);
}
}
var animationInterval = setInterval(animate, 500); // Reset the animation every 5000 milliseconds
}
function generateSnowflakes() {
for (var i = 0; i < 20; i++) { // Create initial snowflakes
createSnowflake();
}
setInterval(createSnowflake, 50); // Create a new snowflake every 500 milliseconds
animateSnowflakes();
}
generateSnowflakes();
function findAndReplace(element) {
if (element.hasChildNodes()) {
element.childNodes.forEach(findAndReplace);
} else if (element.nodeType === Node.TEXT_NODE) {
element.nodeValue = element.nodeValue.replace(/eeerrrggg 🤮/g, 'eeerrrggg 🤮');
}
}
// Perform find and replace in all elements in the document body
findAndReplace(document.body);