Created
November 14, 2012 18:24
-
-
Save steveosoule/4073843 to your computer and use it in GitHub Desktop.
JavaScript Touch Events
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title></title> | |
<script> | |
var gnStartTime = 0; | |
var gbMove = false; | |
var gbStillTouching = false; | |
function checkTapHold(nID) { | |
if ((!gbMove) && (gbStillTouching) && (gnStartTime == nID)) { | |
gnStartTime = 0; | |
gbMove = false; | |
alert('tap hold event'); | |
} | |
} | |
window.addEventListener('touchstart',function(event) { | |
gnStartTime = Number(new Date()); | |
setTimeout('checkTapHold(' + gnStartTime + ');clearTimeout();',2000); | |
},false); | |
window.addEventListener('touchmove',function(event) { | |
gbMove = true; | |
},false); | |
window.addEventListener('touchend',function(event) { | |
gbStillTouching = false; | |
},false); | |
</script> | |
</head> | |
<body> | |
<h1>Click, Hold, and Drag Stuff</h1> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment