add stop bunny animation
This commit is contained in:
@ -6,13 +6,13 @@ const easterEggCount = 20; // count of random extra easter
|
||||
|
||||
const bunny = true; // enable/disable hopping bunny
|
||||
const bunnyDuration = 12000; // duration of the bunny animation in ms
|
||||
const hopHeight = 20; // height of the bunny hops in px
|
||||
const hopHeight = 12; // height of the bunny hops in px
|
||||
const minBunnyRestTime = 2000; // minimum time the bunny rests in ms
|
||||
const maxBunnyRestTime = 5000; // maximum time the bunny rests in ms
|
||||
|
||||
|
||||
let msgPrinted = false; // flag to prevent multiple console messages
|
||||
let rabbitActive = true; // flag to control the bunny animation
|
||||
let animationFrameId;
|
||||
|
||||
// function to check and control the easter
|
||||
function toggleEaster() {
|
||||
@ -27,16 +27,19 @@ function toggleEaster() {
|
||||
// hide easter if video/trailer player is active or dashboard is visible
|
||||
if (videoPlayer || trailerPlayer || isDashboard || hasUserMenu) {
|
||||
easterContainer.style.display = 'none'; // hide easter
|
||||
rabbitActive = false; // stop the bunny animation
|
||||
if (animationFrameId) {
|
||||
cancelAnimationFrame(animationFrameId);
|
||||
animationFrameId = null;
|
||||
}
|
||||
if (!msgPrinted) {
|
||||
console.log('Easter hidden');
|
||||
msgPrinted = true;
|
||||
}
|
||||
} else {
|
||||
easterContainer.style.display = 'block'; // show easter
|
||||
rabbitActive = true; // start the bunny animation
|
||||
let rabbitDiv = document.getElementById("rabbit");
|
||||
animateRabbit(rabbitDiv);
|
||||
if (!animationFrameId) {
|
||||
animateRabbit(); // start animation
|
||||
}
|
||||
if (msgPrinted) {
|
||||
console.log('Easter visible');
|
||||
msgPrinted = false;
|
||||
@ -158,7 +161,6 @@ function animateRabbit(rabbit) {
|
||||
let startTime = null;
|
||||
|
||||
function animationStep(timestamp) {
|
||||
if (!rabbitActive) return;
|
||||
if (!startTime) {
|
||||
startTime = timestamp;
|
||||
|
||||
@ -183,18 +185,18 @@ function animateRabbit(rabbit) {
|
||||
rabbit.style.transform = `translate(${x}vw, ${y}px) scaleX(${rabbit.direction})`;
|
||||
|
||||
if (progress < bunnyDuration) {
|
||||
requestAnimationFrame(animationStep);
|
||||
animationFrameId = requestAnimationFrame(animationStep);
|
||||
} else {
|
||||
// let the bunny rest for a while before hiding easter eggs again
|
||||
const pauseDuration = Math.random() * (maxBunnyRestTime - minBunnyRestTime) + minBunnyRestTime;
|
||||
setTimeout(() => {
|
||||
startTime = null;
|
||||
requestAnimationFrame(animationStep);
|
||||
animationFrameId = requestAnimationFrame(animationStep);
|
||||
}, pauseDuration);
|
||||
}
|
||||
}
|
||||
|
||||
requestAnimationFrame(animationStep);
|
||||
animationFrameId = requestAnimationFrame(animationStep);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user