From 568641fb43b8a4d2c17da4ceb7534e5a598f9b3d Mon Sep 17 00:00:00 2001 From: cadiyak Date: Sat, 27 Aug 2022 16:43:53 +0200 Subject: [PATCH] feat: reset carousel slide timeout when controls or indicators clicked --- src/components/Carousel/Carousel.vue | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/Carousel/Carousel.vue b/src/components/Carousel/Carousel.vue index 7045730..1da32dd 100644 --- a/src/components/Carousel/Carousel.vue +++ b/src/components/Carousel/Carousel.vue @@ -75,15 +75,22 @@ const props = defineProps({ const currentPicture = ref(0) const direction = ref('') +const interval = ref() const automaticSlide = () => { - setInterval(function() { + interval.value = setInterval(function() { nextPicture() }, props.slideInterval) } +const resetInterval = () => { + clearInterval(interval.value) + automaticSlide() +} + const slideTo = (index: number) => { currentPicture.value = index + resetInterval() } const nextPicture = () => { @@ -93,6 +100,7 @@ const nextPicture = () => { currentPicture.value = 0 } direction.value = 'right' + resetInterval() } const previousPicture = () => { @@ -102,6 +110,7 @@ const previousPicture = () => { currentPicture.value = props.pictures.length -1 } direction.value = 'left' + resetInterval() } onMounted(() => {