Options

All options are optional. Pass them as the second argument to new Slider(target, options).

Layout

OptionTypeDefaultDescription
itemsnumber1Number of slides visible at once.
gutternumber0Gap in px between slides.
edgePaddingnumber0Peek px from each side, revealing adjacent slides.
fixedWidthnumber | falsefalseFixed px width per slide instead of fluid columns.
autoWidthbooleanfalseEach slide keeps its own intrinsic width.
centerbooleanfalseCentre the active slide in the viewport.
axis'horizontal' | 'vertical''horizontal'Scroll direction. Vertical requires a fixed container height.

Navigation

OptionTypeDefaultDescription
loopbooleantrueInfinite circular navigation. Clones boundary slides.
rewindbooleanfalseAt the last slide Next jumps back to the first (and vice-versa). Implies loop:false.
slideBynumber | 'page'1Slides advanced per arrow click. 'page' equals items.
startIndexnumber00-based index of the initial slide.
speednumber300Transition duration in ms.
arrowKeysbooleanfalseNavigate with keyboard ← → arrow keys.
preventActionWhenRunningbooleanfalseIgnore nav input while a transition is in progress.

Touch & drag

OptionTypeDefaultDescription
touchbooleantrueEnable touch swipe navigation.
mouseDragbooleanfalseEnable click-and-drag on desktop.
swipeAnglenumber | false15Max degrees from the axis direction to register as a swipe. false disables angle filtering.
preventScrollOnTouch'auto' | 'force' | falsefalseWhether to call preventDefault() on touch events to block page scroll.

Behaviour

OptionTypeDefaultDescription
autoHeightbooleanfalseAnimate container height to match each slide's natural height on transition.
freezablebooleantrueAuto-freeze (disable) when all slides fit on one page.
lazyloadbooleanfalseWait for images to load before the first transform.

Responsive

Pass a responsive map to override any option at specific window widths. Keys are min-width breakpoints in px.

new Slider('#my-slider', {
  items: 1,
  gutter: 8,
  responsive: {
    640:  { items: 2, gutter: 16 },
    960:  { items: 3, gutter: 20 },
    1280: { items: 4, gutter: 24 },
  },
})

All layout and navigation options can be overridden per breakpoint. The slider rebuilds pagination and recalculates layout automatically on each resize that crosses a breakpoint.

Note: plugins cannot be set inside responsive. If you need a plugin only above a certain breakpoint, initialise it conditionally in JS before creating the slider:

const plugins = [arrows()]
if (window.innerWidth >= 960) {
  plugins.push(progress({ container: '#my-progress' }))
}

new Slider('#my-slider', { plugins })

Callbacks & plugins

OptionTypeDefaultDescription
onInitfunction | falsefalseCalled once after the slider is fully initialised. Receives a SliderInfo object.
pluginsSliderPlugin[][]Array of plugin instances. See Plugins.