• Stars
    star
    961
  • Rank 47,587 (Top 1.0 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 10 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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 IE8+.

Support both React.js and Angular.js(v1)

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

NPM

npm i swipejs

Yarn

yarn add swipejs

See the online example for a simple demo.

Import in your project

ES5

const Swipe = require('swipejs');

ES6 and newer

import Swipe from 'swipejs';

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.

Options

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

Options Type Default Description
startSlide Integer 0 index position at which Swipe should start.
speed Integer 300 speed of prev and next transitions in milliseconds.
auto Integer 0 when specified, start an auto-playing slideshow (time in milliseconds between slide change).
continuous Boolean true create an infinite feel with no endpoints.
autoRestart Boolean false auto restart slideshow after user's touch event or next/prev calls.
disableScroll Boolean false prevent any touch events on this container from scrolling the page.
stopPropagation Boolean false stop event propagation.
draggable Boolean false listen to mouse events in addition to the touch events
ignore String null ignore touch events on any element matching this selector
callback Function null 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 null 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,
  ignore: ".scroller",
  callback: function(index, elem, dir) {},
  transitionEnd: function(index, elem) {}
});

API

A Swipe instance exposes the following public methods:

Methods Description
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(options) reinitialize swipe with options.
disable() disable slideshow.
enable() enable slideshow.
kill() completely remove the Swipe instance.

Supports

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

More Repositories

1

awesome-resources

Awesome resources for coding and learning: open source projects, websites, books e.g.
HTML
1,665
star
2

sublime-text-imfix

Fix Sublime Text 3 Input method problem (CJK words) under Ubuntu
C
936
star
3

ewa

Enhanced Wechat App Development Toolkit (微信小程序增强开发工具)。不同于 wepy 或者 mpvue,是一个轻量级小程序开发框架。支持原生小程序所有功能,无需学习,极易上手。支持转换为百度/字节跳动/QQ/支付宝小程序。
JavaScript
183
star
4

smart_sms

The easiest way to integrate SMS service in China
Ruby
91
star
5

qn-webpack

Qiniu webpack plugin (七牛 Webpack 插件)
JavaScript
40
star
6

pretty_doc

Pretty document empowered by markdown language
CSS
9
star
7

ovt

Javascript Object Validation Tool
JavaScript
8
star
8

atom-transpose

Transpose your text. Behave transpose action like Sublime Text 2/3.
CoffeeScript
7
star
9

magico

Magic object accessor for javascript!
JavaScript
6
star
10

dotfiles

My dotfiles
Shell
5
star
11

stoc

String to object compiler for Javascript
JavaScript
4
star
12

rsqoot

A Ruby Wrapper For Sqoot API V2
Ruby
4
star
13

iconcutter

Painless way to resize your icon for all platforms: wechat, weibo, ios, android, and so on
Ruby
4
star
14

railscasts-subscriber

RailsCasts Subscriber with a little hack
Ruby
3
star
15

servant

A Life Servant
JavaScript
2
star
16

system-detective

A detective for your server to find out evils
Ruby
2
star
17

xpick

Extremely powerful pick functionality
JavaScript
2
star
18

ovt-plugin-xss

Ovt plugin for js-xss
JavaScript
2
star
19

lyfeyaj

My Zone ~ 关于技术 & 产品 & 设计的一些思考
2
star
20

jaql

Automatically exported from code.google.com/p/jaql
Java
1
star
21

reminder

Reminder
Ruby
1
star
22

ovt-plugin-lodash

Ovt plugin for lodash
JavaScript
1
star
23

mass-mailer

Mass Mailer
1
star
24

ovt-plugin-baiji

Ovt plugin for baiji
JavaScript
1
star
25

basepack

Front end engineering base toolchain on top of webpack
1
star
26

OpenNash

OpenLDAP Portal System(公司内网LDAP管理,用于企业内部LDAP应用管理,统一入口+员工权限分配)
1
star
27

blog

lyfeyaj's blog
JavaScript
1
star
28

ovt-plugin-validator

Ovt plugin for validator.js
JavaScript
1
star
29

dot-atom

My Atom config and plugins
JavaScript
1
star