Skip to content

Very bad swipe gesture detection, tested on Android and iOS, and of course, desktop browser (Chrome)

Notifications You must be signed in to change notification settings

shvelo/Swipe-gesture.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Swipe-gesture.js

handle swipe gestures on touch devices (also supports mouse click)

Usage:
swipe(element,options) - activate swipe on specified element
swipe(options); - activate swipe on document

Options:
minDistance - int or string - minimum distance between touch start and end positions in pixels or in percents.
unselectable - boolean - disable text selection
onSwipeLeft - function - handler for swipe left
onSwipeRight- function - handler for swipe right
onSwipeUp - function - handler for swipe up
onSwipeDown - function - handler for swipe down

Example

On single element:

swipe(document.getElementbyId('target'),{
	onSwipeRight: function(){
		target.innerHTML = 'Right';
	},
	onSwipeLeft: function(){
		target.innerHTML = 'Left';
	},
	onSwipeDown: function(){
		target.innerHTML = 'Down';
	},
	onSwipeUp: function(){
		target.innerHTML = 'Up';
	},
	minDistance: 0,
	unselectable: true
});

On document:

swipe({
	onSwipeRight: function(){
		alert('Right');
	},
	onSwipeLeft: function(){
		alert('Left');
	},
	onSwipeDown: function(){
		alert('Down');
	},
	onSwipeUp: function(){
		alert('Up');
	},
	minDistance: 0,
	unselectable: false
});

Percent distance

swipe({
	onSwipeRight: function(){
		alert('Right');
	},
	onSwipeLeft: function(){
		alert('Left');
	},
	onSwipeDown: function(){
		alert('Down');
	},
	onSwipeUp: function(){
		alert('Up');
	},
	minDistance: '10%',
	unselectable: false
});

About

Very bad swipe gesture detection, tested on Android and iOS, and of course, desktop browser (Chrome)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published