0.1.13 • Published 5 years ago

swipe-core v0.1.13

Weekly downloads
4
License
ISC
Repository
github
Last release
5 years ago

npm

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
import swiper from 'swipe-core/dist/swipe-core.es'

The UMD build is available on unpkg:

<script src="https://unpkg.com/swipe-core"></script>

Usage

basic: auto cycle

<div id="auto">
  <div>
    <div><img src="./imgs/1.jpg" /> </div>
    <div><img src="./imgs/2.jpg" /> </div>
    <div><img src="./imgs/3.jpg" /> </div>
    <div><img src="./imgs/4.jpg" /> </div>
    <div><img src="./imgs/5.jpg" /> </div>
  </div>
</div>
import swiper from 'swipe-core/dist/swipe-core.es'
var auto = document.getElementById('auto')
swiper({
  root: auto,
  elms: Array.prototype.slice.apply(auto.children[0].children),
  auto: true,
  onEnd: index => console.log(index)
})

expose: expose css cycle two slides

<div id="expose" class="swipe-core-wh">
  <div>
    <div class="swipe-core-wh">
      <div class="box"> <img src="./imgs/1.jpg" /> </div>
    </div>
    <div class="swipe-core-wh">
      <div class="box"> <img src="./imgs/2.jpg" /> </div>
    </div>
  </div>
</div>
import swiper from 'swipe-core/dist/swipe-core.es'
var expose = document.getElementById('expose')
swiper({
  root: expose,
  elms: Array.prototype.slice.apply(expose.children[0].children),
  expose: true,
  css: true
})
#expose { margin-left: 30px; }
.box { padding: 0 5px; }
.swipe-core-wh { width: 315px; height: 200px; }

Options

AttributeDescriptionTypeDefaultValues
autoauto swipeBooleanfalsetrue false
cyclecycle swipeBooleantruetrue false
exposeexpose modeBooleanfalsetrue false
rootroot elementDom element
elmsslides elementsArray[]
indexinitial slide indexNumber0
widthslide widthNumberwindow.screen.width
heightslide heightNumber200
cssuse css to control w/hBooleanfalsetrue false
easeeasingStringcubiccirc cubic
pluginspluginsArray[]

Methods

NameDescriptionParametersReturn
destroydestroy swipe
indexget current indexcurrent index
onadd a event handlerevent name, event handlerunregister function

Events

NameDescriptiontriggerParameters
initinitial-index, current, main, elms
startstart move-index, current, main, elms
moveslides moving-index, current, main, elms
endafter animation-index, current, main, elms
animationEndafter animation-index, current, main, elms

Event handler arguments

NameDescription
indexcurrent index
currentcurrent slide
mainmain dom element
elmsall elements' array

element interface

NameDescription
$indexcurrent index
$prevprevious element
$nextnext element

examples:

// bind 'move'
var off = swiperInstance.on('move', (index, current, main, elms) => {
  // next slide
  console.log(current.$next)
})
// unbind 'move'
off()

Todos

  • performance
  • link list
  • vertical scroll on page
  • group current 3 slides
  • use js to simulate animation
  • ease animating
  • fast drag
  • fast touch
  • swipe left & right
  • disable cycle
  • expose mode
  • support one / two slides
  • dynamic interval
  • auto swipe
  • polyfill requestAnimationFrame
  • polyfill cloneNode deep
  • vendor prefix for transition/transform/translate3d
  • current index interface
  • css width height
  • stop auto swipe when out of screen (android & ios)
  • onEnd
  • onStart | onMove | onEnd
  • dynamic slides
  • init animation
  • desktop
  • inject version info into dist files
0.1.13

5 years ago

0.1.12

5 years ago

0.1.11

5 years ago

0.1.10

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.0.100

6 years ago

0.0.23

6 years ago

0.0.22

6 years ago

0.0.21

6 years ago

0.0.20

6 years ago

0.0.19

6 years ago

0.0.18

6 years ago

0.0.17

6 years ago

0.0.16

6 years ago

0.0.15

6 years ago

0.0.14

6 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

1.0.0

7 years ago