GithubHelp home page GithubHelp logo

axelson / swipe Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lyfeyaj/swipe

0.0 3.0 0.0 815 KB

Swipe is the most accurate touch slider. Support both React and Angular.

Home Page: http://lyfeyaj.github.io/swipe

License: MIT License

JavaScript 64.35% HTML 23.23% CSS 12.15% TypeScript 0.27%

swipe's Introduction

Swipe

Build Status npm version npm GitHub license

Swipe is the most accurate touch slider. It is extremely lightweight (only 6kb minified) and works across all browsers, including IE7+.

Support both Angular.js and React.js

Note

This repo is a continuation of the dead Swipe project. Our mission is to keep Swipe alive and moving forward, with maintenance fixes and new features. Pull Requests are welcome!

Usage

Preview

Preview Image

Thanks to @loup-brun

Installation

You can install this package directly via Bower bower install swipe-js or NPM npm install swipejs.

See the online example for a simple demo.

Markup

Swipe requires just a few lines of markup. 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:

Style

Swipe requires the following styles to be 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;
  overflow: hidden;
}

Javascript

You may initialize a Swipe slider with only one line of javascript code:

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

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

Config Options

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

  • startSlide Integer (default: 0): index position at which Swipe should start.
  • speed Integer (default: 300): speed of prev and next transitions in milliseconds.
  • auto Integer: when specified, start an auto-playing slideshow (time in milliseconds between slide change).
  • draggable Boolean (default: false): enable mouse drag support in desktop browsers.
  • continuous Boolean (default: true): create an infinite feel with no endpoints.
  • autoRestart Boolean (default: false): auto restart slideshow after user's touch event or next/prev calls.
  • disableScroll Boolean (default: false): prevent any touch events on this container from scrolling the page.
  • stopPropagation Boolean (default: false): stop event propagation.
  • callback Function (default: function() {}): runs at slide change. Three parameters are passed to the function: index (the current slide index), elem (the current slide element) and dir (direction: 1 for left or backward, -1 for right or forward).
  • transitionEnd Function (default: function() {}): runs at the end of a slide transition. Two parameters are passed to the function: index (the current slide index) and elem (the current slide element).

Example

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

API

A Swipe instance exposes the following public methods:

  • prev() slide to the previous slide.
  • next() slide to the next slide.
  • getPos(): return the current slide index position.
  • getNumSlides(): return the number of slides.
  • slide(index, duration): slide to the position matching the index (integer) (duration: speed of transition in milliseconds).
  • restart(): restart the slideshow with autoplay.
  • stop(): stop the slideshow and disable autoplay.
  • setup(): reinitialize swipe.
  • kill(): completely remove the Swipe instance.

Browser Support

Swipe is now compatible with all browsers, including IE7+. Swipe works best on devices that support CSS transforms and touch events, 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.

React Support

Please go to react swipe plugin, or check the example

Angular Support

Please go to angular swipe plugin for source code and usage example.

Who's using Swipe

Send me a note if you want your logo here

License

The MIT License (MIT).

swipe's People

Contributors

aaronopfer avatar alicelieutier avatar axelson avatar baer avatar bdougherty avatar benmorel avatar benschwarz avatar chwat avatar cjbell avatar darep avatar designmarco avatar douwem avatar gerrit avatar i-like-robots avatar james2doyle avatar jamesjenner avatar jeroencoumans avatar jonkoops avatar kmiklas avatar lyfeyaj avatar marissamarym avatar mbrubeck avatar pads avatar seebaermichi avatar solidfox avatar stephenway avatar stianlik avatar stutrek avatar thebird avatar x-cray avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.