swipe-core
- 6k before gzip
Demo
Features
Designed for mobile: compact, smooth and efficient
- animation: css animation has limitations, use js to simulate animation
- use requestAnimationFrame and have a compact polyfill
- use cubic bezier to simulate ease out
- always move one element which contain current 3 slides
- a compact link implementation to loop slides
- stop auto swipe when out of screen
- android: IntersectionObserver
- ios: throttle(requestAnimationFrame)
- listen visibilitychange to stop auto swipe when page invisible
Install
$ npm install --save swipe-core
$ yarn add swipe-core
// using ES6 modules
The UMD build is available on unpkg:
Usage
basic: auto
cycle
var auto = document
expose: expose
css
cycle
two slides
var expose = document
Options
Attribute | Description | Type | Default | Values |
---|---|---|---|---|
auto | auto swipe | Boolean | false | true false |
cycle | cycle swipe | Boolean | true | true false |
expose | expose mode | Boolean | false | true false |
root | root element | Dom element | ||
elms | slides elements | Array | [] | |
index | initial slide index | Number | 0 | |
width | slide width | Number | window.screen.width | |
height | slide height | Number | 200 | |
css | use css to control w/h | Boolean | false | true false |
ease | easing | String | cubic | circ cubic |
plugins | plugins | Array | [] |
Methods
Name | Description | Parameters | Return |
---|---|---|---|
destroy | destroy swipe | ||
index | get current index | current index | |
on | add a event handler | event name, event handler | unregister function |
Events
Name | Description | trigger | Parameters |
---|---|---|---|
init | initial | - | index, current, main, elms |
start | start move | - | index, current, main, elms |
move | slides moving | - | index, current, main, elms |
end | after animation | - | index, current, main, elms |
after animation | - | index, current, main, elms |
Event handler arguments
Name | Description |
---|---|
index | current index |
current | current slide |
main | main dom element |
elms | all elements' array |
element interface
Name | Description |
---|---|
$index | current index |
$prev | previous element |
$next | next element |
examples:
// bind 'move'var off = swiperInstance// unbind 'move'
Todos
performancelink listvertical scroll on pagegroup current 3 slidesuse js to simulate animationease animatingfast dragfast touchswipe left & rightdisable cycleexpose modesupport one / two slidesdynamic intervalauto swipepolyfill requestAnimationFramepolyfill cloneNode deepvendor prefix for transition/transform/translate3dcurrent index interfacecss width heightstop auto swipe when out of screen (android & ios)onEndonStart | onMove | onEnd- dynamic slides
- init animation
- desktop
- inject version info into dist files