Auto Scroll
View plugin on GitHubThe Auto Scroll plugin extends Embla Carousel with smooth, continuous scrolling functionality.
Example
Installation
Start by installing the npm package and save it to your dependencies:
<script src="https://unpkg.com/embla-carousel-auto-scroll/embla-carousel-auto-scroll.umd.js"></script>npm install embla-carousel-auto-scroll --savepnpm add embla-carousel-auto-scrollyarn add embla-carousel-auto-scrollOptions
Below follows an exhaustive list of all Auto Scroll options and their default values.
active
booleantrue{ active: false | true }Setting this to false will not activate or deactivate the plugin. Useful when used together with the breakpoints option to toggle the plugin active/inactive depending on media queries.
breakpoints
AutoScrollOptionsType{}{ speed: 1, '(min-width: 768px)': { speed: 2 }}An object with options that will be applied for a given breakpoint by overriding the options at the root level.
Note: If multiple queries match, they will be merged. And when breakpoint options clash, the last one in the list has precedence.
speed
number2{ speed: 2 }Number of pixels auto scroll should advance per frame.
startDelay
number1000{ startDelay: 1000 }Number of milliseconds auto scroll should wait before it starts. This also applies when user interactions end and stopOnInteraction is false.
direction
stringforward{ direction: 'forward' | 'backward' }This option is used to set the auto scroll direction. Set it to backward if you want it to scroll in the opposite direction.
playOnInit
booleantrue{ playOnInit: true | false }If set to false, you'll have to start auto scroll yourself by calling the play method.
stopOnInteraction
booleantrue{ stopOnInteraction: true | false }If set to false, auto scroll will not be disabled after drag interactions, and it will restart every time after an interaction.
stopOnMouseEnter
booleanfalse{ stopOnMouseEnter: true | false }When enabled, auto scroll will stop when a mouse pointer enters the Embla Carousel container. If stopOnInteraction is also false, auto scroll will resume when the mouse leaves the carousel container.
stopOnFocusIn
booleantrue{ stopOnFocusIn: true | false }When enabled, auto scroll will stop when a focusable element inside the carousel recieves focus. If stopOnInteraction is false, auto scroll will resume when the user leaves focus.
rootNode
(emblaRoot: HTMLElement) => HTMLElement | nullnull{ rootNode: null | (emblaRoot) => emblaRoot.parentElement }The node that should respond to user interactions like stopOnMouseEnter and stopOnInteraction. If this is omitted, the node that wraps the Embla Carousel will be used as default.
Methods
Below follows an exhaustive list of all Auto Scroll methods with their respective parameters and return values.
play
(startDelayOverride?: number)voidemblaApi.plugins().autoScroll?.play(1000)Start auto scroll. Pass a startDelayOverride if you want to change the startDelay option after the plugin has been initialized.
stop
nonevoidemblaApi.plugins().autoScroll?.stop()Stops auto scroll.
reset
nonevoidemblaApi.plugins().autoScroll?.reset()Stops auto scroll, and starts the timer again using startDelay when the carousel has settled. This will only take effect if auto scroll is playing. If auto scroll is stopped, this method won't trigger anything.
isPlaying
nonebooleanemblaApi.plugins().autoScroll?.isPlaying()Returns a boolean whether the carousel is auto scrolling or not.
Events
Below follows an exhaustive list of all Auto Scroll events together with information about how they work.
autoScroll:play
emblaApi.on('autoScroll:play', (emblaApi) => {})Fires when auto scroll starts playing.
autoScroll:stop
emblaApi.on('autoScroll:stop', (emblaApi) => {})Fires when auto scroll stops scrolling.