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:
CodeDevMLH
2026-02-27 04:07:29 +01:00
parent 3c1bd01373
commit bd8088c52b
10 changed files with 20 additions and 15 deletions

View File

@@ -252,7 +252,8 @@ function createSpace() {
// Swap to a random image from the pool every time it completes an orbit (disappears)
if (imageArr.length > 1) {
// The animation delay pushes the initial cycle, so we use setInterval matched to duration
setInterval(() => {
const intervalId = setInterval(() => {
if (!document.body.contains(container)) { clearInterval(intervalId); return; }
// Update only if currently out of bounds to avoid popping
const rect = symbol.getBoundingClientRect();
if (rect.right < 0 || rect.left > window.innerWidth) {