Fix spider and mouse creation logic to ensure animations only continue if the container is present in the DOM

This commit is contained in:
CodeDevMLH
2026-02-27 03:58:34 +01:00
parent 73f9be91ef
commit 669ac6d3da

View File

@@ -182,14 +182,18 @@ function createSpider(container) {
setTimeout(() => { setTimeout(() => {
wrapper.remove(); wrapper.remove();
if (document.body.contains(container)) {
setTimeout(() => createSpider(container), Math.random() * 5000 + 1000); setTimeout(() => createSpider(container), Math.random() * 5000 + 1000);
}
}, 500); }, 500);
}); });
wrapper.addEventListener('animationend', () => { wrapper.addEventListener('animationend', () => {
if (isRetreating) return; if (isRetreating) return;
wrapper.remove(); wrapper.remove();
if (document.body.contains(container)) {
setTimeout(() => createSpider(container), Math.random() * 5000 + 1000); setTimeout(() => createSpider(container), Math.random() * 5000 + 1000);
}
}); });
container.appendChild(wrapper); container.appendChild(wrapper);
@@ -223,7 +227,9 @@ function createMouse(container) {
mouse.addEventListener('animationend', () => { mouse.addEventListener('animationend', () => {
mouse.remove(); mouse.remove();
if (document.body.contains(container)) {
setTimeout(() => createMouse(container), Math.random() * 4000 + 2000); setTimeout(() => createMouse(container), Math.random() * 4000 + 2000);
}
}); });
container.appendChild(mouse); container.appendChild(mouse);