From cad8e729b5c483c42731e96893b1916973842bdd Mon Sep 17 00:00:00 2001 From: Vadim Date: Tue, 29 Jun 2021 11:16:34 +0300 Subject: [PATCH] Add goTo method --- src/components/Carousel/Carousel.svelte | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/components/Carousel/Carousel.svelte b/src/components/Carousel/Carousel.svelte index 3b4cdef..66123ed 100644 --- a/src/components/Carousel/Carousel.svelte +++ b/src/components/Carousel/Carousel.svelte @@ -72,6 +72,14 @@ */ export let dots = true + export function goTo(pageIndex, options) { + const animated = get(options, 'animated', true) + if (typeof pageIndex !== 'number') { + throw new Error('pageIndex should be a number') + } + showPage(pageIndex + Number(infinite), { offsetDelayMs: 0, animated }) + } + let store = createStore() let currentPageIndex = 0 $: originalCurrentPageIndex = currentPageIndex - Number(infinite);