Skip to content

Instantly share code, notes, and snippets.

@uupaa
Created December 5, 2012 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uupaa/4214948 to your computer and use it in GitHub Desktop.
Save uupaa/4214948 to your computer and use it in GitHub Desktop.
tap/click time logger
<!DOCTYPE html><html><head><meta charset="utf-8">
<script>
window.onload = function() {
var lastTouchEnd = 0; // last touchend time
document.body.addEventListener("mousedown", touchstart, false);
document.body.addEventListener("mouseup", touchend, false);
document.body.addEventListener("touchstart", touchstart, false);
document.body.addEventListener("touchend", touchend, false);
function touchstart(event) {
var diff = Date.now() - lastTouchEnd;
if (diff <= 16) { // 16ms
alert("I guess you are right: " + diff + " ms");
} else {
console.log(diff);
}
}
function touchend(event) {
lastTouchEnd = Date.now();
}
};
</script>
</head><body>
<p>tap/click time logger</p>
<p>tap me!</p>
</body></html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment