..
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) {
|
||||||
@ -152,22 +150,6 @@ function updateSnowflakes() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// credits: flaticon.com
|
|
||||||
const presentImages = [
|
|
||||||
'images/gift1.png',
|
|
||||||
'images/gift2.png',
|
|
||||||
'images/gift3.png',
|
|
||||||
'images/gift4.png',
|
|
||||||
'images/gift5.png',
|
|
||||||
'images/gift6.png',
|
|
||||||
'images/gift7.png',
|
|
||||||
'images/gift8.png',
|
|
||||||
];
|
|
||||||
|
|
||||||
// credits: https://www.animatedimages.org/img-animated-santa-claus-image-0420-85884.htm
|
|
||||||
const santaImage = 'images/santa.gif';
|
|
||||||
|
|
||||||
/*
|
|
||||||
// credits: flaticon.com
|
// credits: flaticon.com
|
||||||
const presentImages = [
|
const presentImages = [
|
||||||
'seasonals/santa_images/gift1.png',
|
'seasonals/santa_images/gift1.png',
|
||||||
@ -182,7 +164,7 @@ const presentImages = [
|
|||||||
|
|
||||||
// credits: https://www.animatedimages.org/img-animated-santa-claus-image-0420-85884.htm
|
// credits: https://www.animatedimages.org/img-animated-santa-claus-image-0420-85884.htm
|
||||||
const santaImage = 'seasonals/santa_images/santa.gif';
|
const santaImage = 'seasonals/santa_images/santa.gif';
|
||||||
*/
|
|
||||||
|
|
||||||
function createSantaElement() {
|
function createSantaElement() {
|
||||||
const santa = document.createElement('img');
|
const santa = document.createElement('img');
|
||||||
@ -217,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`;
|
||||||
@ -265,6 +262,11 @@ function animateSanta() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
animationFrameIdSanta = requestAnimationFrame(move);
|
animationFrameIdSanta = requestAnimationFrame(move);
|
||||||
|
}
|
||||||
|
|
||||||
|
reloadSantaGif();
|
||||||
|
|
||||||
|
startAnimation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user