Created
December 9, 2011 01:13
-
-
Save lyzadanger/1449628 to your computer and use it in GitHub Desktop.
Quickie swipe thingy with jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Swiper = function(el) { | |
var startX, startY, lastX, lastY; | |
var minswipe; | |
var init=function(el) { | |
Swiper.minswipe = 50; | |
el.bind('touchstart', function(event) { | |
Swiper.startX = event.originalEvent.targetTouches[0].screenX; | |
Swiper.startY = event.originalEvent.targetTouches[0].screenY; | |
$(this).bind('touchmove', function(event) { | |
Swiper.lastX = event.originalEvent.targetTouches[0].screenX; | |
Swiper.lastY = event.originalEvent.targetTouches[0].screenY; | |
if(Math.abs(Swiper.startX - Swiper.lastX) > Swiper.minswipe) { | |
$(this).unbind('touchmove'); | |
$(this).trigger('swiper'); | |
if (Swiper.lastX > Swiper.startX) { | |
$(this).trigger('swiperedright'); | |
} | |
else { | |
$(this).trigger('swiperedleft'); | |
} | |
Swiper.reset(); | |
} | |
}); | |
}); | |
}(el); | |
var reset = function() { | |
Swiper.startX = 0; | |
Swiper.startY = 0; | |
Swiper.lastX = 0; | |
Swiper.lastY = 0; | |
}; | |
}; | |
$(document).ready(function() { | |
if (Modernizr.touch) { | |
Swiper($('#tracktouches')); | |
Swiper($('#tracktouches2')); | |
$('#tracktouches').bind('swiperedleft', function() { | |
alert('tracktouches ONE went left'); | |
}); | |
$('#tracktouches2').bind('swiperedleft', function() { | |
alert('tracktouches TWO went left'); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment