fixed intervals to timeouts

This commit is contained in:
2026-01-20 22:44:30 +00:00
parent 25dc5e0a97
commit c25e9263fd
2 changed files with 15 additions and 10 deletions

View File

@@ -14,22 +14,24 @@ const currentIndex = ref(0);
const currentComment = computed(() => images[currentIndex.value].comment);
const currentUrl = computed(() => images[currentIndex.value].url);
let nextId;
function nextImage() {
clearTimeout(nextId);
let newIndex;
do {
newIndex = Math.floor(Math.random() * images.length);
} while (newIndex === currentIndex.value); // prevent same image repeating
} while (newIndex === currentIndex.value);
currentIndex.value = newIndex;
nextId = setTimeout(nextImage, 10000);
}
let intervalId;
onMounted(() => {
intervalId = setInterval(nextImage, 10000);
nextId = setTimeout(nextImage, 10000);
});
onUnmounted(() => {
clearInterval(intervalId);
clearTimeout(nextId);
});
</script>