Created
April 10, 2014 18:42
-
-
Save nbrew/10410706 to your computer and use it in GitHub Desktop.
Deal with touch events on a list. (Touch duration, swipe.)
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 timeout, | |
longtouch, | |
xDown, | |
yDown; | |
$("#myList li").bind('touchstart', function() { | |
timeout = setTimeout(function() { | |
longtouch = true; | |
}, 300); | |
}).bind('touchend', function() { | |
if (longtouch) { | |
// It was a long touch. | |
} | |
longtouch = false; | |
clearTimeout(timeout); | |
}); | |
$("#myList") | |
.on('mousedown touchstart', function (e) { | |
xDown = e.originalEvent.touches[0].pageX; | |
yDown = e.originalEvent.touches[0].pageY; | |
swiped = false; | |
}) | |
.on('mouseup touchend',function (e) { | |
var xUp = e.originalEvent.changedTouches[0].pageX; | |
var yUp = e.originalEvent.changedTouches[0].pageY; | |
console.log("(x,y) = (" + xUp + "," + e.yUp +")"); | |
if (xDown != xUp || yDown != yUp) { | |
console.log("xDistance: " + (xUp - xDown)); | |
console.log("yDistance: " + (yUp - yDown)); | |
swiped = true; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment