神刀安全网

Universal version of Brad Birdsall's Swipe.js

Universal (a.k.a isomorphic) Swipe.js

Universal version of Brad Birdsall's Swipe.js Universal version of Brad Birdsall's Swipe.js

Fork of originalSwipe in order to be published to NPM (has no deps) and being compatible with isomorphic apps. Install it like:

npm install swipe-js-iso

PRO HINT: UseReactSwipe component with React .

Usage

Swipe only needs to follow a simple pattern. Here is an example:

<div id='slider' class='swipe'>   <div class='swipe-wrap'>     <div></div>     <div></div>     <div></div>   </div> </div>

Above is the initial required structure– a series of elements wrapped in two containers. Place any content you want within the items. The containing div will need to be passed to the Swipe function like so:

window.mySwipe = Swipe(document.getElementById('slider'));

I always place this at the bottom of the page, externally, to verify the page is ready.

Also Swipe needs just a few styles added to your stylesheet:

.swipe {   overflow: hidden;   visibility: hidden;   position: relative; } .swipe-wrap {   overflow: hidden;   position: relative; } .swipe-wrap > div {   float:left;   width:100%;   position: relative; }

Config Options

Swipe can take an optional second parameter– an object of key/value settings:

  • startSlideInteger (default:0) – index position Swipe should start at

  • speedInteger (default:300) – speed of prev and next transitions in milliseconds.

  • autoInteger – begin with auto slideshow (time in milliseconds between slides)

  • continuousBoolean (default:true) – create an infinite feel with no endpoints

  • disableScrollBoolean (default:false) – stop any touches on this container from scrolling the page

  • stopPropagationBoolean (default:false) – stop event propagation

  • swipingFunction – invoked while swiping with the percentage (0-1) of the full width that has been swiped.

  • callbackFunction – runs at slide change.

  • transitionEndFunction – runs at the end slide transition.

Example

window.mySwipe = new Swipe(document.getElementById('slider'), {   startSlide: 2,   speed: 400,   auto: 3000,   continuous: true,   disableScroll: false,   stopPropagation: false,   callback: function(index, elem) {},   transitionEnd: function(index, elem) {} });

Swipe API

Swipe exposes a few functions that can be useful for script control of your slider.

prev() slide to prev

next() slide to next

getPos() returns current slide index position

getNumSlides() returns the total amount of slides

slide(index, duration) slide to set index position (duration: speed of transition in milliseconds)

Browser Support

Swipe is now compatible with all browsers, including IE7+. Swipe works best on devices that support CSS transforms and touch, but can be used without these as well. A few helper methods determine touch and CSS transition support and choose the proper animation methods accordingly.

Who’s using Swipe

Universal version of Brad Birdsall&#x27;s Swipe.js Universal version of Brad Birdsall&#x27;s Swipe.js Universal version of Brad Birdsall&#x27;s Swipe.js Universal version of Brad Birdsall&#x27;s Swipe.js Universal version of Brad Birdsall&#x27;s Swipe.js Universal version of Brad Birdsall&#x27;s Swipe.js

License

Copyright (c) 2013-2015 Brad Birdsall Licensed under the The MIT License (MIT) .

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » Universal version of Brad Birdsall's Swipe.js

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
分享按钮