Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
S

Swipe

> 编程语言
Open source

Swipe is the most accurate touch slider.

6.7K stars0 likes3 views
WebsiteGitHub

About

Swipe is the most accurate touch slider.

Usage

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

xml

    

    

  </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:

javascript
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:

css
.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

javascript

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).

Issues· 242 open

View all issuesOpen on GitHub
  • #490

    Carousel speed is quicker on mobile, how I fix it?

    Updated Aug 16, 2023
  • #551

    Can I use it with vue?

    Updated Mar 21, 2021
  • #547

    调用slide方法后,自动滑动失效

    Updated Mar 13, 2021
  • #550

    Extra space on left

    Updated Sep 15, 2020
  • #418

    Start callback

    Updated Mar 12, 2019
  • #542

    Gaps between each slider item in latest Safari

    Updated Nov 20, 2018
  • #341

    The auto swiping stops when manually swipe is done check (swipejs.com)

    Updated Jul 12, 2018
  • #545

    Processing version of Swipe

    Updated Apr 17, 2018
  • #544

    Swipe does not work android mobile browser.

    Updated Feb 17, 2018
  • #537

    Show multiple slides

    Updated Jan 14, 2018

> Tags

JavaScript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 23, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言