1.0.9 • Published 4 years ago

svelte-swipeable v1.0.9

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

svelte-swipeable

Lightweight library to handle swipe gestures in Svelte

Animation Component demo

Installation

npm i svelte-swipeable

Animation component

import { Animate } from 'svelte-swipeable';
 <Animate 
     direction=any 
     stiffness=0.2 
     damping=0.2 
     willReturn=true 
     momentum=0.2
     options={options}
     swipeUp={hanldeSwipe}>

     <div>Content</div>
    
 </Animate>       

Events

EventTriggered
swipeUpAfter swiping up
swipeDownAfter swiping down
swipeRightAfter swiping right
swipeLeftAfter swiping left
swipeStartAfter mousedown on element
swipeMoveAfter moving element
swipeEndAfter mouseup on element

Event Data

DataDefinition
xCoordinate of new X
yCoordinate of new Y
initialObject containing initial x and y coordinates
directionObject containing x direction and y direction
// Assuming a swipe up of 200px

function handleSwipe(event) {
   console.log(event.detail.initial.y); //0
   console.log(event.detail.y); //200
   console.log(event.detail.direction.y); //up
}

Options

These thresholds will take effect on all direction-specific events. Default is 0px.

let options = {
   threshX: 100, // threshold in x before event is triggered (px)
   threshY: 200 // threshold in y before event is triggered (px)
};

Svelte Action Usage

import swipe from 'svelte-swipeable';
<div use:swipe="{options}" on:swipeUp="{handleSwipe}">
   Content
</div>
1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago