# snap-touch

> A touch enabled slider for horizontal navigation

Latest version **1.0.6** (published 2017-09-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install snap-touch
pnpm add snap-touch
yarn add snap-touch
bun add snap-touch
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2017-09-14 |
| First published | 2017-04-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Justin Bull |
| Maintainers | jabes |
| Keywords | slider, gallery, menu, navigation, snap, flick, swipe, swipeable, gestures, velocity, momentum, accelerated, transitions, responsive, drag, draggable, touch, mouse, javascript |

## Links

- npm: https://www.npmjs.com/package/snap-touch
- Repository: https://github.com/jabes/snap-touch
- Homepage: https://jabes.github.io/snap-touch/
- Issues: https://github.com/jabes/snap-touch/issues
- npm.io page: https://npm.io/package/snap-touch

## Alternatives

- [adhdev](https://npm.io/package/adhdev.md) — 11.1K weekly downloads
- [react-slide-button](https://npm.io/package/react-slide-button.md) — 310 weekly downloads
- [better](https://npm.io/package/better.md) — 42 weekly downloads
- [react-native-swipe-image](https://npm.io/package/react-native-swipe-image.md) — 22 weekly downloads
- [nl.fokkezb.pulltorefresh](https://npm.io/package/nl.fokkezb.pulltorefresh.md) — 11 weekly downloads

## Recent versions

- 1.0.6 (latest) — 2017-09-14
- 1.0.5 — 2017-04-12
- 1.0.4 — 2017-04-06
- 1.0.2 — 2017-04-05
- 1.0.1 — 2017-04-05
- 1.0.0 — 2017-04-05

## 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](https://jabes.github.io/snap-touch/)

### 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

```html
<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>
```

```javascript
new SnapTouch('slider').create();
```

```css
.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:

```javascript
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:

```javascript
const slider = new SnapTouch('slider').create();
slider.addEventListener(
    'SnapTouch.positionChanged',
    function (event) {
        console.log('posX: ' + event.detail.posX);
    }
);
```

---
_Source: https://npm.io/package/snap-touch · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
