Touch events for svelte.js
npm install @ls-age/svelte-touch> Touch events for svelte.js
``bash`
npm install --save[-dev] @ls-age/svelte-touch
In svelte component
`html
`
In regular browser environment
`javascript
import { swipe } from '@ls-age/svelte-touch';
const elm = document.getElementById('swipe-target');
swipe(elm, event => {
console.log(event);
});
`
All gestures can be customized by passing options to them. **Note that you'll have to import from the ./events folder in this case.
Example
`javascript
import swipe from '@ls-age/svelte-touch/events/swipe';
// This handler requires a finger to move at least 50 pixels to the left to detect a swipe gesture
const customSwipe = swipe({
threshold: 50,
});
// Use customSwipe just like swipe was used in the above examples`
A single tap.
Options
- maxDuration (number=150) The maximum duration of the touch event in milliseconds.maxMovement
- (number=20) The maximum distance of the touch event in pixels.
A swipe gesture.
Options
- axis (SwipeAxis=SwipeAxis.all) The axis to accept swipes on.direction
- (SwipeDirection=SwipeDirection.all) The direction to accept swipes to.threshold
- (number=30`) The minimum distance a finger has to move until a swipe is recognized.
Shortcuts for swipe gestures restriced to specific directions or axis.
More to come soon