Add checks for container presence in animation functions to prevent errors when elements are removed from the DOM [skip ci]
This commit is contained in:
@@ -238,7 +238,7 @@ function animateSanta() {
|
||||
function startAnimation() {
|
||||
const santaHeight = santa.offsetHeight;
|
||||
if (santaHeight === 0) {
|
||||
setTimeout(startAnimation, 100);
|
||||
setTimeout(() => { if (document.body.contains(santa)) startAnimation(); }, 100);
|
||||
return;
|
||||
}
|
||||
// console.log('Santa height: ', santaHeight);
|
||||
@@ -283,7 +283,7 @@ function animateSanta() {
|
||||
animationFrameIdSanta = requestAnimationFrame(move);
|
||||
} else {
|
||||
const pause = Math.random() * ((maxSantaRestTime - minSantaRestTime) * 1000) + minSantaRestTime * 1000;
|
||||
setTimeout(animateSanta, pause);
|
||||
setTimeout(() => { if (document.body.contains(santa)) animateSanta(); }, pause);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user