From e6953b6b92e70f5af8d891653de8a6da7749609e Mon Sep 17 00:00:00 2001 From: David Jerleke Date: Sat, 13 Jan 2024 21:46:07 +0100 Subject: [PATCH] Add reset method --- .../src/components/AutoScroll.ts | 9 +++++++++ .../src/content/pages/plugins/auto-scroll.mdx | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/packages/embla-carousel-auto-scroll/src/components/AutoScroll.ts b/packages/embla-carousel-auto-scroll/src/components/AutoScroll.ts index 3942f3336..9d48562db 100644 --- a/packages/embla-carousel-auto-scroll/src/components/AutoScroll.ts +++ b/packages/embla-carousel-auto-scroll/src/components/AutoScroll.ts @@ -22,6 +22,7 @@ export type AutoScrollType = CreatePluginType< { play: (delay?: number) => void stop: () => void + reset: () => void isPlaying: () => boolean }, OptionsType @@ -228,6 +229,13 @@ function AutoScroll(userOptions: AutoScrollOptionsType = {}): AutoScrollType { if (playing) stopScroll() } + function reset(): void { + if (playing) { + stopScroll() + startScrollOnSettle() + } + } + function isPlaying(): boolean { return playing } @@ -239,6 +247,7 @@ function AutoScroll(userOptions: AutoScrollOptionsType = {}): AutoScrollType { destroy, play, stop, + reset, isPlaying } return self diff --git a/packages/embla-carousel-docs/src/content/pages/plugins/auto-scroll.mdx b/packages/embla-carousel-docs/src/content/pages/plugins/auto-scroll.mdx index e0f2e1f88..8d9c94c7a 100644 --- a/packages/embla-carousel-docs/src/content/pages/plugins/auto-scroll.mdx +++ b/packages/embla-carousel-docs/src/content/pages/plugins/auto-scroll.mdx @@ -148,6 +148,15 @@ Stops auto scroll. --- +### reset + +Parameters: `none` +Returns: `void` + +Stops auto scroll and starts over. This will only take effect if auto scroll is playing. If auto scroll is stopped, this method won't trigger anything. + +--- + ### isPlaying Parameters: `none`