Last active
August 29, 2015 14:06
-
-
Save Krelix/95804a184dd314dbaf9d to your computer and use it in GitHub Desktop.
Simple HTML page that register a first click and increments a timer until the mouse click is registered again on the page.
This file contains hidden or 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 lang="en"> | |
<meta charset="utf-8" /> | |
<script type="text/javascript"> | |
var timer; | |
var myTimeout; | |
var updateTime = function(myTime){ | |
document.getElementById("timer").textContent = myTime; | |
} | |
var timeoutFunction = function(){ | |
updateTime(new Date().getTime() - timer); | |
clearTimeout(myTimeout); | |
myTimeout = setTimeout(timeoutFunction, 2); | |
} | |
window.onload = function(){ | |
var body = document.body; | |
body.style.margin = '0px'; | |
body.style.padding = '0px'; | |
body.style.width = "100%"; | |
body.style.height = window.innerHeight + "px"; | |
body.onclick = function(e){ | |
console.log("click"); | |
if(timer){ | |
clearTimeout(myTimeout); | |
console.log("second click obtained"); | |
updateTime(new Date().getTime() - timer) | |
timer = undefined; | |
} else { | |
console.log("setting timer"); | |
timer = new Date().getTime(); | |
myTimeout = setTimeout(timeoutFunction, 2); | |
} | |
}; | |
}; | |
</script> | |
</head> | |
<body> | |
<div style="font-size: large;"><span id="timer">0</span> ms.</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment