A very small (3,77kb minified), barebones jQuery gallery/slider plugin. This plugin, unlike many other slider plugins, does not include any DOM controls, transitions or styling. It only keeps track of the gallery's state and provides a simple API to create additional interaction. This makes it extremely lightweight and flexible.
To initialize a new gallery:
let gallery = $(container).tinySlides([options]);
To allow for the gallery object to expose an API, default jQuery method chaining is broken.
This means that after using tinySlides()
, no jQuery methods can be chained.
The element to initialize the gallery on. The HTML of your container may look something like this, where .gallery is the container.
<div class="gallery">
<ul class="gallery-slides">
<li class="gallery-slide"></li>
</ul>
</div>
The plugin accepts several options,
slideSelector
DOM selector for a single slide in the gallery. Default is '.gallery-slide'activeClass
: Class name for indicating the current slide. Default is 'active'start
: The default starting slide. This may also be defined in the HTML by adding the class 'active' to a slide. Default is 0autoplay
: Default is falseautoresume
: Resume playing after an interaction. Default is true,duration
: Duration of each slide in play mode. Can be both a Number and a function that accepts a jQuery object with the current slide. Default is 2000keyboard
: Can be used to disablekeyboardArrows
andkeyboardSpace
. Default is truekeyboardArrows
: Allow using the left and right arrow keys to navigate the slides. Default is falsekeyboardSpace
: Allow using the spacebar to move to the next slide. Default is falseonChange
: Callback that runs after the slide index has changedonBeforeChange
: Callback that runs before the slide index changesonPlay
: Callback that runs when autoplay is activatedonStop
: Callback that runs after autoplay is stoppedonReady
: Callback that runs the first time theawait
callback returns falseawait
: Skip autoplay iterations while this callback returns true. This can be used to only start playing until after an event has occurred, such as loading an image. Default is (slides, current) => false,eventNamespace
: Namespace for the plugin API events. Default is pluginName.toLowerCase()
These options can later be modified using the setting()
API method.
This plugin exposes an API that allows interaction with the gallery from outside of the plugin.
By binding the gallery to a variable, the plugin's API methods can be used later in the code:
let gallery = $(container).tinySlides([options]);
gallery.next();
gallery.current()
Returns the current slidegallery.slides()
Returns all slidesgallery.next()
Move to the next slidegallery.previous()
Move to the previous slidegallery.goto(index)
Move to a specific slidegallery.play()
Resume play modegallery.stop()
Pause play modegallery.setting(option, value)
Update one of the plugin's optionsgallery.destroy()
Stop the gallery. Returns undefined, so you can destroy the gallery by usinggallery = gallery.destroy()
.gallery.end()
Go back to jQuery's default methode chaining. Basically, this method returns$(container)
.
These events will fire after the callbacks defined under Options.
All events are prefixed with eventNamespace
from the options.
tinyslideschange
tinyslidesbeforechange
tinyslidesplay
tinyslidesstop
tinyslidesready
Copyright 2017 Bastiaan ten Klooster
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.