From 3d782b21eadef0d9ba5a0670a28af9fe7890650f Mon Sep 17 00:00:00 2001 From: Lena Date: Tue, 2 Jun 2026 12:16:24 +0200 Subject: [PATCH] Endlosschleife Chips beendet?! --- js/script.js | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/js/script.js b/js/script.js index df418f7..83400e2 100644 --- a/js/script.js +++ b/js/script.js @@ -1,31 +1,37 @@ // Chipsregen -console.log ("Meine Seite läuft"); +console.log("Meine Seite läuft"); +// Chips erstellen function createChip() { - const chip = document.createElement("img"); - chip.src = "img/Chips.png"; - + chip.src = "img/Chips.png"; // ggf. Pfad prüfen chip.classList.add("chip"); + const size = Math.random() * 50 + 50; + chip.style.width = size + "px"; + chip.style.left = Math.random() * window.innerWidth + "px"; - chip.style.animationDuration = - (Math.random() * 3 + 3) + "s"; - - chip.style.width = - (Math.random() * 50 + 50) + "px"; + const duration = Math.random() * 3 + 3; + chip.style.animationDuration = duration + "s"; document.body.appendChild(chip); - setTimeout(() => { + // Entfernen nach Animation (besser als fixe Zeit) + chip.addEventListener("animationend", () => { chip.remove(); - }, 6000); + }); } -setInterval(createChip, 300); +// Start / Stop Logik (optional aber empfehlenswert) +const chipInterval = setInterval(createChip, 300); + +// optional: nach 30 Sekunden stoppen +setTimeout(() => { + clearInterval(chipInterval); +}, 30000);