Created
December 6, 2013 02:15
-
-
Save hagino3000/7817522 to your computer and use it in GitHub Desktop.
Check click event delay of device browser
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> | |
<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 '); | |
}); | |
link.addEventListener('mousedown', function() { | |
addTime('mouse down '); | |
}); | |
link.addEventListener('mouseup', function() { | |
addTime('mouse up '); | |
}); | |
link.addEventListener('click', function() { | |
addTime('click '); | |
setTimeout(function() { | |
finished = true; | |
}); | |
}); | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment