Git Product home page Git Product logo

swipe's Introduction

SwipeFade 1.0 - based on Swipe

Swipe is a lightweight mobile slider with 1-to-1 touch movement. For more info read the blog post.

Demo

Visit here on a touch-enabled mobile device swipejs.com

Usage

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

<div id='slider'>
  <ul>
  	<li style='display:block'></li>
  	<li style='display:none'></li>
  	<li style='display:none'></li>
  	<li style='display:none'></li>
  	<li style='display:none'></li>
  </ul>
</div>

Above is the initial required structure– a series of elements wrapped in two containers. An unordered list makes sense here, but this can be any combination of elements that has the same structure. (more on the display:block/none reasoning below).Place any content you want within the items. The containing div will need to be passed to a new Swipe object like so:

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 Swipe should start at

  • speed Integer (default:300) - speed of prev and next transitions in milliseconds.

  • breakPoint Integer (default:0) - specifies which breakpoint width to change from fading to sliding.

  • auto Integer - begin with auto slideshow (time in milliseconds between slides)

  • callback Function - runs at the end of any slide change. (effective for updating position indicators/counters)

Example

window.mySwipe = new Swipe(document.getElementById('slider'), {
	startSlide: 2,
	speed: 400,
	breakPoint: 1024,
    auto: 3000,
	callback: function(event, index, elem) {

	  // do something cool

	}
});

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

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

Requirements

Modernizr with csstransitions is required for the library to run.

jQuery is required for backwards compability, if csstransitions is not supported by the browser.

This is why I set all elements but the first list item to display:none– if the device doesn't pass the feature tests then it will fallback to displaying only the first item.

Let's Make It Better

I would love to hear more about how to improve Swipe. Play with it and let me know how you use and please fork away. If you have any questions, contact me on Twitter or GitHub.

License

Swipe mobile slider is © 2011 Brad Birdsall and is licensed under the terms of GPL & MIT licenses.

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.