Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

swipejs

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swipejs

Swipe is the most accurate touch slider

  • 2.3.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.3K
decreased by-7.9%
Maintainers
1
Weekly downloads
 
Created
Source

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:

OptionsTypeDefaultDescription
startSlideInteger0index position at which Swipe should start.
speedInteger300speed of prev and next transitions in milliseconds.
autoInteger0when specified, start an auto-playing slideshow (time in milliseconds between slide change).
continuousBooleantruecreate an infinite feel with no endpoints.
autoRestartBooleanfalseauto restart slideshow after user's touch event or next/prev calls.
disableScrollBooleanfalseprevent any touch events on this container from scrolling the page.
stopPropagationBooleanfalsestop event propagation.
draggableBooleanfalselisten to mouse events in addition to the touch events
ignoreStringnullignore touch events on any element matching this selector
callbackFunctionnullruns 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).
transitionEndFunctionnullruns 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:

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

Keywords

FAQs

Package last updated on 01 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc