Controller

You're browsing the documentation for v3

Overview

The Controller component parses the request into the proper index and propagates it to the Move component.

Methods

go()

go( control: number | string, allowSameIndex?: boolean ): void

Moves the slider by the following control pattern. Splide#go() is the alias of this method.

i

Goes to the slide i

'+${i}'

Increments the slide index by i

'-${i}'

Decrements the slide index by i

'>'

Goes to the next page

'<'

Goes to the previous page

'>${i}'

Goes to the page i

Params

control

A control pattern.

allowSameIndex

Optional. Determines whether to allow to go to the current index or not.

callback

Optional. A callback function invoked after transition ends.


scroll()

scroll( destination: number, useIndex?: boolean, snap?: boolean, duration?: number, callback?: AnyFunction ): void

Scrolls the slider to the specified destination or index with updating current and previous indices.

Params

destination

A position or an index to scroll to. The useIndex must be true to specify the index.

useIndex

Optional. Whether to use an index as a destination or not.

snap

Optional. Whether to snap the closest slide or not.

duration

Optional. Specifies the scroll duration. If omitted, it is computed by distance.

callback

Optional. A callback function invoked after scroll ends.


getNext()

getNext( destination?: boolean ): number

Returns a next index. By default, this method resolves the clone index to the real slide index - for example, -1 will be length - 1, but if the destination is true, the method returns -1 as it is.

This method can also return -1 even if the destination is false, which means there is no next slide to go.

Params

destination

Optional. Determines whether to get a destination index or a slide index.

Return

A next index if available, or otherwise -1.


getPrev()

getPrev( destination?: boolean ): number

Returns a previous index. By default, this method resolves the clone index to the real slide index - for example, -1 will be length - 1, but if the destination is true, it does not.

This method can also return -1 even if the destionation is false, which means there is no previous slide to go.

Params

destination

Optional. Determines whether to get a destination index or a slide index.

Return

A previous index if available, or otherwise -1.


getEnd()

getEnd(): number

Returns the end index where the slider can go. For example, if the slider has 10 slides and the perPage option is 3, the slider can go to the slide 8 (the index is 7).

Return

An end index.


setIndex()

setIndex( index: number ): void

Updates the current index. This method just updates the internal variable and nothing happens to the slider.

Return

A new index to set.


getIndex()

getPrev( prev?: boolean ): number

Returns the current or previous index. Splide#index is the alias of the Controller#getIndex().

Params

prev

Optional. Determines whether to return previous (old) index or not.


toIndex()

toIndex( page: number ): number

Converts the page index to the slide index.

Params

page

A page index to convert.

Return

A slide index.


toPage()

toPage( index: number ): number

Converts the slide index to the page index.

Params

page

An index to convert.

Return

A page index.