Swipe is the most accurate touch slider.

Overview

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:

  • startSlide Integer (default:0) - index position Swipe should start at

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

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

  • continuous Boolean (default:true) - create an infinite feel with no endpoints

  • disableScroll Boolean (default:false) - stop any touches on this container from scrolling the page

  • stopPropagation Boolean (default:false) - stop event propagation

  • callback Function - runs at slide change.

  • transitionEnd Function - 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

  • CNN
  • Craigslist
  • Airbnb
  • NHL
  • many more…

License

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

Comments
  • Problem with Jquery mobile

    Problem with Jquery mobile

    Hi! I'm working on a mobile html5 app for my company and have found your swipe script the absolute best.

    There seems to be one problem though. I'm using Jquery mobile and the swipe function won't work so good. I have noticed the problem may have something to do with the display:block.

    For example:

    This code won't work, it only shows the first pic and nothing more:

    <div style='display:block'><img src="img/1.jpg" width="100%"></div>
    <div style='display:none'><img src="img/2.jpg" width="100%"></div>
    <div style='display:none'><img src="img/3.jpg" width="100%"></div>
    

    But if i set the other div to display:block also, it will work. But when the page loads that divs "flashes" by. And thats not so pretty.

    Like this:

    <div style='display:block'><img src="img/1.jpg" width="100%"></div>
    <div style='display:block'><img src="img/2.jpg" width="100%"></div>
    <div style='display:none'><img src="img/3.jpg" width="100%"></div>
    

    Any ideas of why?

    Thank you for your great work.

    opened by patriklund 29
  • iframes inside slides

    iframes inside slides

    I’m trying to put iframe player from YouTube and Vimeo but SwipeJS behaves very strange when you put iframes as content inside slides.

    • it seems like iframe is catching all touch events so only way you can swipe left/right is when you touch area outside iframe
    • YouTube player acts very strange in a way that it doesn’t show iframe content but when you tap on empty area player activates and upon pausing video everything shows correctly

    I’ve tried with their respective JS APIs but, as with iframes, they’re also very buggy and "beta-ish" so support is not standardized across platforms.

    opened by niksy 23
  • added an option

    added an option "circular"

    The circular option can be use for swiping always forward. When you reach the end, you go back to the first sliding in the same direction, so the slider seems endless.

    I could not do this in the no transition fallback, though, because it would mean manipulating the dom (actually changing the order of the element in the list and recalculating indexes..).

    Tell me what you think, if I need to change something, etc.

    opened by alicelieutier 20
  • added start and stop to API. Fixed issue #341: slideshow does not resume after touch event.

    added start and stop to API. Fixed issue #341: slideshow does not resume after touch event.

    Start() and Stop()

    This allows easier manipulation from outside of the plugin.

    For example, a pause on a hover event is now simple: $('.swipe').hover(function() { $(this).data('Swipe').stop(); }, function() { $(this).data('Swipe').start(); });

    Slideshow Resume

    Previously, the slideshow would no longer cycle automatically after touch interaction.

    Added paused variable to maintain state from stop() API call

    This should close issues #341, #322, #316, #242

    opened by trose 14
  • Swipe js goes haywire when contained elements have animations

    Swipe js goes haywire when contained elements have animations

    I am creating a feature on a site that has several animations on each slide. The library I am using is GSAP, green sock. Long story short I got all my animations dialed in and when I integrated swipe js the elements within the slide container jump all over the place. It swipes left and right and that works fine but if a slide that I swipe to contains any animations that particular slide goes haywire. This only happens when a slide contains animations.

    Has this happened to any one?

    opened by jessepinuelas 14
  • Using slide() it's seems duration is override by duration set before

    Using slide() it's seems duration is override by duration set before

    I set it up to auto slide. and when i click a button with slide function it seems that the first duration i set overrides the duration in slide(index, duration)

    Isn't there a pause function?

    opened by tattoodobem 13
  • Orientation Change Crashes iOS

    Orientation Change Crashes iOS

    Hi, Brad.

    I'm a web designer for Carnegie Mellon University. Thanks for Swipe. We used it for the web version of what we call the "brag book." It's a mini-book containing the unique accomplishments of our students, alumni and faculty.

    Check it out: www.cmu.edu/brag cmu-brag-screenshot

    It's responsive and looks great on most devices. Unfortunately, it crashes when changing orientation on iOS. Have you heard of this happening for other people? Do you know what we could do to fix it?

    Thanks! Steve

    opened by SteveChab 10
  • IE8 & 9 autoscroll issue

    IE8 & 9 autoscroll issue

    I'm using Swipe2 on the following page: http://www.greeleytribune.com/News/ and it works great with just about every important browser except for IE8 & IE9. In those two browsers, the autoscroll stops after the 2nd slide. I'm not seeing any errors in the console and I can advance to the next slide with next(). My code needs some refactoring, but I've even tried a barebones implementation and have had no luck.

    I know that the focus of Swipe is not IE, but Swipe2 says that it does support IE. So, just wondering if anyone else has run into this issue or perhaps Swipe2 supports IE with the exception that the autoscroll doesn't work.

    Thanks!

    opened by sjferwerda 10
  • Not Working on Samsung Galaxy S2

    Not Working on Samsung Galaxy S2

    Sorry i do not know what version of Android this is, but it is a very new phone.

    The demo page, swipejs.com , does not work with the swipe gesture. Previous and next do work.

    opened by ecurtis 10
  • Callback not always fired

    Callback not always fired

    If you swipe very quickly several times it seems like the transition end event doesn't get fired (assuming because the actual transition doesn't fire?). This can be seen in the example below (mobile safari doesn't seem to like jsfiddle), everytime the callback is called we prepend to the list with the index. Press on the next link slowly and you see all callbacks, press quickly and you see we miss some indexes:

    http://jsfiddle.net/4a2yy/3/

    A hacky workaround is to call the callback at the end of the swipe function. I did this in the demo below, calling it within a setTimeout as otherwise it effects how smooth the transition appears in mobile safari.

    http://jsfiddle.net/VecTR/9/

    opened by owain 10
  • Swipe does not work for win8 (ie10)

    Swipe does not work for win8 (ie10)

    Windows handles events in a other way. Mouse, touch and pen get merged. Because of a other structure in the events swipe.js does not work for win8 (ie10).

    Added extra checks in the code for win8, if ie10, handle events in a other way.

    opened by MartvanKoolwijk 8
  • Extra space on left

    Extra space on left

    https://codepen.io/guyr989/pen/OJNwJmy

    Hey I am using version 5. I know you are no longer supporting it but I've looked everywhere and tried a lot of different things. I have this huge space on the left(using rtl) on desktop. Wierdly enough it wokrs perfectly on codepen but if you copy the files to your local machine than you can see it. (on the first time on codepen it may replicate as well).

    image

    image

    opened by Guyr989-zz 0
  • Processing version of Swipe

    Processing version of Swipe

    Hi there

    Looking for a solid Slider option for my Processing project, I found Swipe and thought it would be my best option. So I kind of ported it, in its simplest form, to Processing, the Graphic Programming language for Artists and Designers

    You'll find it here https://github.com/rich-gg/PSwipe

    The purpose of this post is not to advertise but to ask if what I've done is ok for you and if I can keep it on in GitHub

    Congratulation for Swipe, it is really nice rich

    opened by rich-gg 0
  • Swipe does not work android mobile browser.

    Swipe does not work android mobile browser.

    Swiping right/left does not work on android while it works on iOS devices. When i run my application on iOS devices, i am able to swipe and also auto slide works well but when it comes to android only auto slides works and not swipe events. Its a Hybrid application and uses same JS for both the devices. Please help me out with the issue.

    opened by RohanSRaikar 0
  • Gaps between each slider item in latest Safari

    Gaps between each slider item in latest Safari

    I'm pretty sure it was working on older versions of Safari, but I've recently found a bug where each image (slider/swipe item) is not loading the next image until the previous one is off the screen and causing a gap between images. This happens after 2-3 clicks on the next() slide.

    It's tricky to explain so I've recorded a quick screencast to demonstrate: https://www.dropbox.com/s/hwbi16481ygmb16/swipe-safari-issue.mov?dl=0

    All other browsers are working fine and wondering if anyone else is having the same issue.

    macOS: 10.13.2 Safari: 11.0.2 Swipe: 2.0.0

    const slider = document.getElementsByClassName('slider')
    for (var i = 0; i < slider.length; i++) {
    
    	const sliderCount = slider[i].dataset.moduleCount
    	const prev = document.querySelector('.slider__prev-' + sliderCount)
    	const next = document.querySelector('.slider__next-' + sliderCount)
    	const swipe = document.querySelector('.swipe-' + sliderCount)
    
    	window.mySwipe = new Swipe(swipe, {
    		startSlide: 0,
    		speed: parseInt(swipe.dataset.speed),
    		auto: parseInt(swipe.dataset.delay),
    		draggable: true,
    		continuous: true,
    		disableScroll: false,
    		stopPropagation: false,
    		callback: function (index, elem, dir) {},
    		transitionEnd: function (index, elem) {}
    	})
    
    	prev.onclick = mySwipe.prev
    	next.onclick = mySwipe.next
    
    	if (mySwipe.getNumSlides() === 1) {
    		prev.classList.add('hide')
    		next.classList.add('hide')
    	}
    }
    

    Any help would be appreciated.

    opened by jackbarham 2
  • Width calculation rounding - Edge browser

    Width calculation rounding - Edge browser

    The width calculation of the parent of swipe-element creates an issue wherein the last swipe-element does not display on higher resolutions 1920x1080. On lower resolution this problem does not seem to occur.

    The issue being with the Math.round for calculating the width of the parent.

    For example I'm displaying 63 images in the swipe inside modal, the width is 76185px in Chrome and in Edge is 76185.69px but the last image does not display, if I go and increase the width by one pixel the image display. This does not occur for the cases only for some only in Edge browser.

    opened by jbizkit 0
Owner
Brad Birdsall
Brad Birdsall
Smooth mobile touch slider for Mobile WebApp, HTML5 App, Hybrid App

iSlider iSlider is a lightweight, high-performant, no library dependencies cross-platform slide controller. It can help handling most sliding effects,

Baidu BEFE 1.7k Nov 25, 2022
Super tiny size multi-touch gestures library for the web.    You can touch this →

Preview You can touch this → http://alloyteam.github.io/AlloyFinger/ Install You can install it via npm: npm install alloyfinger Usage var af = new Al

腾讯 AlloyTeam 3.3k Dec 12, 2022
Pressure is a JavaScript library for handling both Force Touch and 3D Touch on the web

Pressure is a JavaScript library for handling both Force Touch and 3D Touch on the web, bundled under one library with a simple API that makes working with them painless.

Stuart Yamartino 2.9k Dec 29, 2022
The PatternFly Design Kit is a Sketch library used for creating PatternFly accurate design mockups

PatternFly Design Kit The PatternFly Design Kit is a collection of Sketch assets that make it easy for designers to create high-fidelity design mockup

PatternFly 44 Jan 2, 2023
This project is a user friendly project that provides the accurate constellation name of the user

OVERVIEW: This is a group project by certain members of the 100Devs community. Contributors Lee Gill | GitHub: LeeGee64 | Twitter: @LeeGee64 | LinkedI

Lee Gill 5 Jun 15, 2022
↔️ Swipe through Home Assistant Dashboard views on mobile.

Home Assistant Swipe Navigation Swipe through Home Assistant Dashboard views on mobile. This repository has been forked from maykar/lovelace-swipe-nav

Zanna_37 71 Dec 26, 2022
MenuSlider-Javascript - How to create a menu slider with vanilla javascript

MenuSlider-Javascript How to create a menu slider with vanilla javascript Instal

Tarokh Mohammadi 1 Feb 8, 2022
A Responsive JQuery Slider

Turntable.js :: A Responsive JQuery Slider A jQuery plugin that will flip through a list of images as your mouse sweeps across a container Usage All i

Polar Notion 518 Nov 1, 2022
A dependency-free JavaScript ES6 slider and carousel. It’s lightweight, flexible and fast. Designed to slide. No less, no more

Glide.js is a dependency-free JavaScript ES6 slider and carousel. It’s lightweight, flexible and fast. Designed to slide. No less, no more What can co

null 6.7k Jan 3, 2023
A lightweight, modern and customizable JavaScript slider library.

NSlider NSlider is a lightweight (< 10 KB), modern and customizable JavaScript slider library. CDN Development https://cdn.jsdelivr.net/gh/fatihege/ns

Fatih 6 Jan 20, 2022
A very simple image slider that will responsively work with images of any size or shape

Square1 A very simple image slider that will responsively work with images of any size or shape. requires jQuery Demo Installation Link to jQuery <sc

Thom 9 May 20, 2022
UI slider control that magnifies the current value

jquery-rsSliderLens Renders a powerfull input range control. With minor differences, all browsers render an <input type="range" /> pretty much the sam

Jose Rui Santos 21 Apr 22, 2022
Tool Cool Range Slider

Responsive range slider library written in typescript and using web component technologies. Pure JavaScript without additional dependencies. It has a rich set of settings, including a vertical slider, touch, mousewheel and keyboard support, local and session storage, and RTL support.

Tool Cool 23 Dec 31, 2022
Rotating slider for selecting numerical values.

Rotating slider for selecting numerical values. Allows mobile friendly precise selection for value from selected range with desired step. Component is especially useful for hybrid application using frameworks like Ionic, Cordova or PhoneGap.

null 0 Sep 27, 2022
Pure JavaScript HTML5 Canvas Range Slider. No stylesheet needed. Simple, elegant and powerful. A quirky alternative to other sliders.

CanvasSlider CanvasSlider is a lightweight JavaScript range slider. Most of the range slider controls use Javascript and a stylesheet. This slider use

null 7 Aug 15, 2022
Slide everything into this vanilla javascript slider: just 20kb all-inclusive, no dependencies!

Lightweight vanilla javascript media and contents slider, by LCweb Just 20KB to have: Top features list: single file, no dependencies, 100% pure javas

Luca 4 May 12, 2021
Custom touch bar or digital macropad app for GNU/Linux 🐧 using an Android device 📱

?? Boar ??️ Custom touch bar or digital macropad app for GNU/Linux ?? using an Android device ?? Those apps allow creating a keyboard with custom keys

Fabián Velosa 0 Oct 29, 2022
Polyfill to remove click delays on browsers with touch UIs

FastClick FastClick is a simple, easy-to-use library for eliminating the 300ms delay between a physical tap and the firing of a click event on mobile

FT Labs 18.8k Jan 2, 2023
A pleasing darker theme made mostly with complementary purple and blue colors, occasionally with a touch of pink or red.

Nebula Float away in space with a beautiful blurple oriented color theme. DISCLAIMER: ⚠️ This theme is not as high contrast as other themes. A pleasin

catgirlkelly 5 Nov 23, 2022