Giter Club home page Giter Club logo

snap-touch's Introduction

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

NAME PARAMETERS TYPE DESCRIPTION
create
destroy
getActiveIndex
setActiveIndex index (int) The index of the slide to activate.
getGosition
setPosition posX (number) The slider position to set in pixels.
Example:
const slider = new SnapTouch('slider').create();
slider.setActiveIndex(2);

Events

NAME PARAMETERS TYPE DESCRIPTION
SnapTouch.created
SnapTouch.destroyed
SnapTouch.activeIndexChanged index (int) The index of the current slide.
SnapTouch.trackingStart
SnapTouch.trackingEnd
SnapTouch.tracking now (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.positionChanged posX (number) The current position in pixels.
SnapTouch.easePositionEnd posX (number) The current position in pixels.
SnapTouch.resized slideWidth (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);
    }
);

snap-touch's People

Contributors

jabes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

almendro

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.