Socket
Socket
Sign inDemoInstall

snap-touch

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    snap-touch

A touch enabled slider for horizontal navigation


Version published
Weekly downloads
58
decreased by-18.31%
Maintainers
1
Created
Weekly downloads
 

Changelog

Source

[1.0.6] - 2017-09-14

Changed

  • Renamed repo from SnapTouch to snap-touch (sorry)

Readme

Source

Snap Touch

A touch enabled slider for horizontal navigation

This slider calculates velocity to decelerate when flicked and will snap to an element when finished.

View demo

How To Use

Install with NPM

npm install snap-touch --save

Use a CDN

https://unpkg.com/snap-touch/snap-touch.js
https://unpkg.com/snap-touch/snap-touch.min.js

Features

  • No dependencies
  • Modern JavaScript (ES6)
  • IE9+ compatible
  • Responsive

Example

<div id="slider" class="slider">
    <div class="slides">
        <div class="slide"></div>
        <div class="slide"></div>
        <div class="slide"></div>
        <div class="slide"></div>
        <div class="slide"></div>
    </div>
</div>
new SnapTouch('slider').create();
.slider {
    overflow: hidden;
    padding-left: 50%;
    padding-right: 50%;
}

.slides {
    margin-left: -100px;
    margin-right: -100px;
    white-space: nowrap;
    font-size: 0;
}

.slide {
    display: inline-block;
    width: 200px;
    height: 200px;
    box-sizing: border-box;
    border: 2px solid white;
    background: black;
}

Methods

NAMEPARAMETERSTYPEDESCRIPTION
create
destroy
getActiveIndex
setActiveIndexindex(int)The index of the slide to activate.
getGosition
setPositionposX(number)The slider position to set in pixels.
Example:
const slider = new SnapTouch('slider').create();
slider.setActiveIndex(2);

Events

NAMEPARAMETERSTYPEDESCRIPTION
SnapTouch.created
SnapTouch.destroyed
SnapTouch.activeIndexChangedindex(int)The index of the current slide.
SnapTouch.trackingStart
SnapTouch.trackingEnd
SnapTouch.trackingnow(number)The time in milliseconds.
timeElapsed(number)Time elapsed since last tracking step in milliseconds.
delta(number)Difference between the last position and the current.
velocity(number)The calculated velocity based on delta.
posX(number)The current position in pixels.
lastPosX(number)The last tracking step position in pixels.
lastTimestamp(number)The last tracking step time in milliseconds.
SnapTouch.positionChangedposX(number)The current position in pixels.
SnapTouch.easePositionEndposX(number)The current position in pixels.
SnapTouch.resizedslideWidth(number)The width of an individual slide in pixels.
slideTotal(int)The total number of slides.
Example:
const slider = new SnapTouch('slider').create();
slider.addEventListener(
    'SnapTouch.positionChanged',
    function (event) {
        console.log('posX: ' + event.detail.posX);
    }
);

Keywords

FAQs

Last updated on 14 Sep 2017

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc