Options

All options passed to the Slider constructor. All are optional with sensible defaults.

Layout

OptionTypeDefaultDescription
slidesPerPagenumber | 'auto'1Number of slides visible per page.
gutternumber0Gap in pixels between slides.
edgePaddingnumber0Padding in pixels on both edges of the container, peeking next/prev slides.
direction'horizontal' | 'vertical''horizontal'Slide direction.
centeredbooleanfalseCenter the active slide.

Behavior

OptionTypeDefaultDescription
loopbooleanfalseInfinite loop via DOM clones.
rewindbooleanfalseJump from last to first (and vice versa) without clones.
speednumber300Transition duration in ms.
grabCursorbooleantrueShow grab cursor on hover.
startIndexnumber0Initial active slide index.
freezablebooleantrueFreeze (disable interaction) when all slides fit on one page.
disabledbooleanfalseInitialize in disabled state.

Touch & drag

OptionTypeDefaultDescription
touchbooleantrueEnable touch events.
mouseDragbooleanfalseEnable mouse drag.
swipeThresholdnumber50Minimum swipe distance in px to trigger navigation.
swipeAnglenumber15Max angle (degrees) to consider a swipe valid.
resistancebooleantrueAdd resistance at the edges.
resistanceRationumber0.85Resistance multiplier (0–1).
preventScrollOnTouch'auto' | 'force' | false'auto'Prevent page scroll during horizontal swipe.

Responsive / Breakpoints

const slider = new Slider('#el', {
  slidesPerPage: 1,
  gutter: 0,
  breakpoints: {
    768: { slidesPerPage: 2, gutter: 16 },
    1024: { slidesPerPage: 3, gutter: 24, edgePadding: 32 },
  },
})

Breakpoint keys are min-width values. Options merge with the base config at each breakpoint.

Accessibility

OptionTypeDefault
a11y.enabledbooleantrue
a11y.prevSlideMessagestring'Previous slide'
a11y.nextSlideMessagestring'Next slide'
a11y.slideLabelstring'{"{"index}} of {"{"total}}'

Plugins

import { arrows, pagination } from '@andresclua/sliderkit-plugins'

new Slider('#el', {
  plugins: [arrows(), pagination({ type: 'dots' })],
})

Events (on init)

new Slider('#el', {
  on: {
    afterSlideChange: ({ index, previousIndex }) => {
      console.log('Went from', previousIndex, 'to', index)
    },
    progress: ({ progress }) => {
      progressBar.style.width = progress * 100 + '%'
    },
  },
})