Tiny flickable slideshow. 1.8kb gzipped.
The immediate children of the slideshow element will be transformed into slides.
<div id='slider'>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
Basically, it'll work out of the box without any CSS, but it'll look terrible. I
recommend specifying the width of the slider, and the height and/or width of the
slides. noodle
will calculate its height based on the height of the first
slide.
That's pretty much it.
import noodle from 'noodle'
const slider = noodle(document.getElementById('slider'))
noodle
accepts a single options object
as its second parameter.
noodle(node, options)
By default, noodle
calculates slider height based on the active slide. To
disable, set to false
.
Set to false
to disabled the default behavior or focusing the slideshow and
active slide after user interaction.
Set the initial active slide of the slideshow. Default: 0
.
Fired immediately on slide selection.
slider.on('select', index => {})
Fired after the slider settles to its active index.
slider.on('settle', index => {})
slider.index // => 3
slider.on('select', index => {})
Return the current index.
slider.index // => 0
slider.select(3)
slider.prev()
slider.next()
Recalculate slider height and slides position. Use this if the DOM updates or after images load.
slider.resize()
slider.destroy()
Re-initialize a destroyed slideshow.
slider.init()
When it comes to slideshows, Flickity sets the bar. @metafizzy's article, Math Time: Resting Position was incredibly helpful, and I doubt I would have figured out the velocity maths without it.
Many thanks to gentooist for allowing me to have
the name noodle
. Very kind of them!
MIT License © Eric Bailey