methods
prev()
and next()
Move the slider to show the previous or next slides
const slider = new BlazeSlider(options)
slider.prev() // move 1 slide to the left
slider.next() // move 1 slide to the right
slider.prev(2) // move 2 slides to the left
slider.next(2) // move 2 slides to the right
onSlide()
Listen for slide change event
const slider = new BlazeSlider(options)
const unsubscribe = slider.onSlide(
(pageIndex, firstSlideIndex, lastSlideIndex) => {
// do something
}
)
// when you no longer need to listen for slide change events
unsubscribe()
The callback function will be called with the following arguments:
pageIndex
- the index of the current slidefirstSlideIndex
- the index of the first visible slide in the current pagelastSlideIndex
- the index of the last visible slide in the current page
Calling the unsubscribe
function returned by the onSlide()
will remove the event listener for the slide change event.
stopAutoplay()
Stops the slider autoplay.
const slider = new BlazeSlider(options)
// when you want to stop the autoplay
slider.stopAutoplay()
destroy()
Destroy the slider instance. Removes all event listeners, stops the autoplay, removes pagination buttons added via javascript
const slider = new BlazeSlider(options)
slider.destroy()
refresh()
Refresh the slider instance. This will recalculate the slider dimensions and reposition the slides.
This is useful if slides are added or removed from the slider after the slider has been initialized.
By default, refresh
is automatically called on window resize.
const slider = new BlazeSlider(options)
slider.refresh()