autoplay

Auto-advances slides on a timer. Pauses on hover, focus, and optionally on visibility change.

Import

import { autoplay } from '@andresclua/sliderkit-plugins'

Usage

new Slider('#el', {
  loop: true,
  plugins: [
    autoplay({
      delay: 3000,
      pauseOnHover: true,
      pauseOnFocus: true,
      stopOnLastSlide: false,
      resetOnVisibility: true,
    }),
  ],
})

Options

OptionTypeDefaultDescription
delaynumber3000Time in ms between slide advances.
pauseOnHoverbooleantruePause when the mouse is over the slider.
pauseOnFocusbooleantruePause when a focusable element inside has keyboard focus.
stopOnLastSlidebooleanfalseStop permanently when the last slide is reached.
resetOnVisibilitybooleantrueReset timer when the tab becomes visible again (Page Visibility API).
reverseDirectionbooleanfalseAuto-advance backwards.

Control via slider instance

const slider = new Slider('#el', { plugins: [autoplay()] })

slider.play()   // start autoplay
slider.pause()  // pause autoplay

Demo

View autoplay demo →