npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

snap-touch

v1.0.6

Published

A touch enabled slider for horizontal navigation

Downloads

255

Readme

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);
    }
);