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
'+${i}'
'-${i}'
'>'
'<'
'>${i}'

Params

control
allowSameIndex
callback

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
duration
snap
callback

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

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

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).


setIndex()

setIndex( index: number ): void

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


getIndex()

getPrev( prev?: boolean ): number

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

Params

prev

toIndex()

toIndex( page: number ): number

Converts the page index to the slide index.

Params

page

toPage()

toPage( index: number ): number

Converts the slide index to the page index.

Params

page

isBusy()

isBusy(): boolean

Checks if the carousel can move now or not.