Skip to content

Instantly share code, notes, and snippets.

@hagino3000
Created December 6, 2013 02:15
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 hagino3000/7817522 to your computer and use it in GitHub Desktop.
Save hagino3000/7817522 to your computer and use it in GitHub Desktop.
Check click event delay of device browser
<!doctype html>
<html>
<head>
<title>Touch Event Test</title>
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, target-densityDpi=device-dpi" />
<style>
html {
height: 100%;
}
body {
height: 100%;
font-family: monospace;
font-size: 20px;
}
</style>
</head>
<body>
<a href="#" id="link">Touch me!!</a>
</body>
<script>
var finished = false;
var prevTime = null;
function addTime(eventName) {
if (finished) return;
var now = Date.now();
var el = document.createElement('div');
var label = "";
if (prevTime == null) {
prevTime = now;
label = 'Start.......';
} else {
label = (now - prevTime) + 'ms';
}
el.innerHTML = eventName + ':' + label;
document.body.appendChild(el);
}
var link = document.getElementById('link');
link.addEventListener('touchstart', function() {
addTime('touch start');
});
link.addEventListener('touchend', function() {
addTime('touch end&nbsp;&nbsp;');
});
link.addEventListener('mousedown', function() {
addTime('mouse down ');
});
link.addEventListener('mouseup', function() {
addTime('mouse up&nbsp;&nbsp; ');
});
link.addEventListener('click', function() {
addTime('click&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
setTimeout(function() {
finished = true;
});
});
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment