HammerSlider touch
Check out the demo
Yet another touch slider. Yada yada yada...
HammerSlider is a lightweight slider with infinite carousel and rewind features.
Comes with customizable settings and its own API for extensibility.
- Works with Mousedrag Events, Touch Events, Pointer Events and IE10 Pointer Events.
- Only 8.6k minified. ~3.3k with Gzip.
- IE10+ compatible.
- Library agnostic. If jQuery is available, it will register itself as a plugin.
- API and callback functions for extensibility.
- Animates with CSS3 transforms and requestAnimationFrame for smooth sliding.
Install
$ npm install hammer-slider
Kit
Usage
HTML markup:
<div class="c-slider" id="hammer-slider">
<div class="c-slider__container">
<div class="c-slider__slide">
...
</div>
<div class="c-slider__slide">
...
</div>
<div class="c-slider__slide">
...
</div>
</div>
</div>
JavaScript:
const slider = HammerSlider(document.getElementById('hammer-slider'));
Or JavaScript + jQuery:
$('#hammer-slider').HammerSlider();
You may place anything you want within the slides.
Settings
HammerSlider accepts an object as an optional second parameter. Default settings are:
{
slideSpeed: 50,
touchSpeed: 50,
startSlide: 0,
slideShow: false,
slideInterval: 5000,
stopAfterInteraction: true,
rewind: false,
mouseDrag: false,
minimumDragDistance: 30,
dragThreshold: 10,
cssPrefix: 'c-slider',
dots: false,
dotContainer: undefined,
slideContainer: undefined,
beforeSlideChange: undefined,
afterSlideChange: undefined,
onSetup: undefined
}
API
HammerSlider exposes a set of functions upon setup that can be used to control the slider externally:
next();
prev();
stop();
start();
getActiveSlideNr();
moveTo(number, speed);
setupSlider(number);
Examples
JavaScript
const slider = HammerSlider(document.getElementById('hammer-slider'), {
slideSpeed: 60,
slideShow: true,
slideInterval: 4000,
dots: true,
mouseDrag: true,
beforeSlideChange: (targetSlide) => {
console.log('Changing to slide number: ' + targetSlide);
}
});
document.getElementById('next-btn').addEventListener('click', slider.next, false);
JavaScript + jQuery
const slider = $('#hammer-slider').HammerSlider({
slideSpeed: 60,
slideShow: true,
slideInterval: 4000,
dots: true,
mouseDrag: true,
beforeSlideChange: (targetSlide) => {
console.log('Changing to slide number: ' + targetSlide);
}
});
$('#next-btn').on('click', slider.data('HammerSlider').next);
License
MIT license