Skip to content

Instantly share code, notes, and snippets.

@steveosoule
Created November 14, 2012 18:24
Show Gist options
  • Save steveosoule/4073843 to your computer and use it in GitHub Desktop.
Save steveosoule/4073843 to your computer and use it in GitHub Desktop.
JavaScript Touch Events
<!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