Restart animation on viewport change

This commit is contained in:
ernstmul
2024-12-27 06:59:34 +01:00
parent fbf10a46e7
commit 82d64af13c
@@ -10,7 +10,15 @@
let currentSentenceIndex = 0;
let visible = true;
function handleResize() {
startAnimation = false;
setTimeout(() => {
startAnimation = true;
}, 1500);
}
onMount(() => {
window.addEventListener('resize', handleResize);
const interval = setInterval(() => {
visible = false;
currentSentenceIndex = (currentSentenceIndex + 1) % loadingSentences.length;
@@ -19,7 +27,10 @@
}, 1000);
}, 5000);
return () => clearInterval(interval);
return () => {
clearInterval(interval);
window.removeEventListener('resize', handleResize);
};
});
</script>