Created
June 23, 2014 09:11
-
-
Save peyerluk/6b74ca6c1764af356165 to your computer and use it in GitHub Desktop.
SwipeEvents (jQuery plugin)
This file contains hidden or 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
# Credit: Eike Send for the awesome swipe event | |
# --------------------------------------------- | |
# | |
# https://github.com/peachananr/onepage-scroll | |
$.fn.swipeEvents = -> | |
return this.each -> | |
startX = startY = undefined | |
$this = $(this) | |
$this.bind('touchstart', touchstart) | |
touchstart = (event) -> | |
touches = event.originalEvent.touches | |
if touches?.length | |
startX = touches[0].pageX | |
startY = touches[0].pageY | |
$this.bind('touchmove', touchmove) | |
touchmove = (event) -> | |
touches = event.originalEvent.touches | |
if touches?.length | |
deltaX = startX - touches[0].pageX | |
deltaY = startY - touches[0].pageY | |
if deltaX >= 50 | |
$this.trigger("swipeLeft") | |
if deltaX <= -50 | |
$this.trigger("swipeRight") | |
if deltaY >= 50 | |
$this.trigger("swipeUp") | |
if deltaY <= -50 | |
$this.trigger("swipeDown") | |
if Math.abs(deltaX) >= 50 || Math.abs(deltaY) >= 50 | |
$this.unbind('touchmove', touchmove) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment