Controller

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 carousel 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, duration?: number, snap?: boolean, callback?: AnyFunction ): void

Scrolls the carousel to the specified destination with updating current and previous indices. This method uses the Scroll component to move the carousel instead of CSS transition.

Params

destination

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

duration

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

snap

Optional. Whether to snap the closest slide or not.

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 carousel can go. For example, if the carousel has 10 slides and the perPage option is 3, the carousel 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 carousel.

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.


isBusy()

isBusy(): boolean

Checks if the carousel can move now or not.

Return

true if the carousel can move, or otherwise false.