Simple slide manager ๐ซ Focused on animations.
npm add slidemanagerimport Slidemanager from 'slidemanager'
const slider = new Slidemanager({
el: document.querySelector('#gallery'),
callback({ current, previous, direction, done }) {
// Your animations here
// ...
// Call done() when your animation is complete
done()
}
})- ๐ผ
el: DOM element to attach the swipe event to. If not given, please provide alengthparameter. - โน๏ธ
callback: function called when user swipes or slide changes automatically. - ๐ย
loop: whether to stop at the last / first slide or not. (Defaultfalse) โถ๏ธ ยauto: set it totrueto automatically switch to the next slide. (Defaultfalse)- โฏ
interval: specifies the interval in seconds between each slide change.automust betrue. (Default5) โ๏ธ ยvertical: if set totrue, the swipe movement to change the current slide will need to be vertical. (Defaultfalse)- ๐ข
length: number of slides. If not given, The number of slides will be the number ofel's children - *๏ธโฃย
swipe: iffalse, the swipe touch movement detection is disabled. (Defaulttrue) - ๐
mouseSwipe: Whether the swipe movement must be checked on the mouse or not. (Defaultfalse) - ๐ย
random: Switch to random slides instead of next and previous ones. Enables automatically theloopoption. (Defaultfalse) - #๏ธโฃย
startAt: The index from which to start the slider on initialization. (Default0) - โญ
threshold: Amount of pixels required to change slide when swiping (Default60) - โบ
init: Whether to init the manager immediately or not. Iffalse, call the.init()method to initialize the manager. (Defaulttrue)
- ๐
prev(): goes to the previous slide - ๐
next(): goes to the next slide - ๐
goTo(index, data): goes to the specified index, you can pass data which can be recovered in the callback - ๐ฆ
start()/stop(): starts / stops the automatic sliding - ๐
init(): adds event listeners. Call this when theinitoption is set tofalse - โฐ๏ธ
destroy(): removes event listeners and stops the slider
The callback function receives a parameter containing the following properties :
current: New indexprevious: Previous indexdirection: 1 for next, -1 for previousdone: the function to call when you're done with your animationsdata: some data that may be given from a call togoTo()
The returned Slidemanager instance exposes the following properties :
index: The current indexmax: The last element's indexchanging: Whether the slider is currently moving or not
MIT, see LICENSE.md for details.