`<pacem-swipe>` is a *behavior* that makes elements swipeable, with a feel for physics: drag them far enough, or fling them fast enough, and they fly.
Swipe cards, swipe-to-archive rows, pull-to-refresh; mouse or finger.
```html
<pacem-swipe id="cards" snaps="-600,0,600"
on-swiperightanimationend="if ($event.detail.snap) { #likes.model++; }"></pacem-swipe>
<pacem-panel behaviors="{{ [#cards] }}">…</pacem-panel>
```
## Usage
**Attach it.** List the behavior in the elements' `behaviors`. `direction` is `horizontal` (default) or `vertical`.
**Place the snaps.** `snaps` are the offsets (in pixels) where an element may come to rest, `0` being home.
On release, the element flies to the snap nearest to where its momentum would carry it (`detail.predictedDelta`):
a short, slow drag lands back on `0`. The snap it's headed to is `detail.snap`, known from the release on.
**React.** Every release fires `swipe`, then `swipeleft` / `swiperight` / `swipeup` / `swipedown` (cancelable: stop the flight);
once the element has landed, `swipeanimationend` and its directional twin. `pan` fires while dragging.
> The events fire on **every** release, a bounce back home included: check `$event.detail.snap`
> (`0` means back home) before acting.
> The element then **stays** on its snap. To bring it home (say, to show the next card in the same element),
> clear its transform, as below. With `options.autoresetSpans` it may instead keep going, its snaps re-centered on where it landed.
```html
<pacem-swipe snaps="-600,0,600" on-swipeanimationend="$event.detail.element.style.transform = ''"></pacem-swipe>
```
**Fine-tune.** `options` takes `inertia` (how far a fling carries, default 8), `start` (pixels before a drag begins, default 32),
`fling` (default 400), `bouncy` (drag past the last snap and bounce back, default `true`), `autoresetSpans`.
`handle-selector` limits where the gesture can start.
## Customization
A swipeable element gets `.pacem-swipe`, which the theme gives `touch-action: none` (the browser doesn't scroll, the swipe takes the finger).
On a horizontally swipeable list that blocks vertical scrolling over the rows: let the browser keep the vertical axis.
```css
.my-inbox .pacem-swipe { touch-action: pan-y; }
```
## Examples
### Swipe to archive iOS Mail style: swipe a row left (far or fast enough) and it's archived; the row element then comes back home, showing the next message.
### Pull to refresh `direction="vertical"`: pull the panel down far enough and it refreshes, then gets put back.
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.