fix santa height
This commit is contained in:
@@ -39,8 +39,6 @@ function toggleSnowfall() {
|
|||||||
initializeCanvas();
|
initializeCanvas();
|
||||||
snowflakes = createSnowflakes(santaContainer);
|
snowflakes = createSnowflakes(santaContainer);
|
||||||
animateAll();
|
animateAll();
|
||||||
} else {
|
|
||||||
console.warn('could not initialize santa: animation frame is already running');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msgPrinted) {
|
if (msgPrinted) {
|
||||||
@@ -201,17 +199,32 @@ function dropPresent(santa, fromLeft) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function reloadSantaGif() {
|
||||||
|
const santa = document.querySelector('.santa');
|
||||||
|
const src = santa.src;
|
||||||
|
santa.src = '';
|
||||||
|
santa.src = src;
|
||||||
|
}
|
||||||
|
|
||||||
function animateSanta() {
|
function animateSanta() {
|
||||||
const santa = document.querySelector('.santa');
|
const santa = document.querySelector('.santa');
|
||||||
|
|
||||||
|
function startAnimation() {
|
||||||
|
const santaHeight = santa.offsetHeight;
|
||||||
|
if (santaHeight === 0) {
|
||||||
|
setTimeout(startAnimation, 100);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// console.log('Santa height: ', santaHeight);
|
||||||
|
|
||||||
const screenWidth = window.innerWidth;
|
const screenWidth = window.innerWidth;
|
||||||
const screenHeight = window.innerHeight;
|
const screenHeight = window.innerHeight;
|
||||||
const fromLeft = Math.random() < 0.5;
|
const fromLeft = Math.random() < 0.5;
|
||||||
const startX = fromLeft ? -220 : screenWidth + 220;
|
const startX = fromLeft ? -220 : screenWidth + 220;
|
||||||
const endX = fromLeft ? screenWidth + 220 : -220;
|
const endX = fromLeft ? screenWidth + 220 : -220;
|
||||||
const santaHeight = santa.offsetHeight;
|
const startY = Math.random() * (screenHeight / 5) + santaHeight; // Restrict to upper screen
|
||||||
const startY = Math.random() * (screenHeight / 5 - santaHeight - 50) + 50; // Restrict to upper screen
|
const endY = Math.random() * (screenHeight / 5) + santaHeight; // Restrict to upper screen
|
||||||
const endY = Math.random() * (screenHeight / 5 - santaHeight - 50) + 50; // Restrict to upper screen
|
const angle = Math.random() * 16 - 8; // -8 to 8 degrees
|
||||||
const angle = Math.random() * 20 - 10; // -10 to 10 degrees
|
|
||||||
|
|
||||||
santa.style.left = `${startX}px`;
|
santa.style.left = `${startX}px`;
|
||||||
santa.style.top = `${startY}px`;
|
santa.style.top = `${startY}px`;
|
||||||
@@ -249,6 +262,11 @@ function animateSanta() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
animationFrameIdSanta = requestAnimationFrame(move);
|
animationFrameIdSanta = requestAnimationFrame(move);
|
||||||
|
}
|
||||||
|
|
||||||
|
reloadSantaGif();
|
||||||
|
|
||||||
|
startAnimation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user