-
onMouseDown Timer
Is there any script floating around that accurately times how long the mouse is held down and returns this as a value in seconds? I think this would be a really cool script to have, and if it is not around a fun one to make! I think I will try my hand at it if no one responds... I am crap with the whole timing concept. This could be interesting =P
-
Code:
<div id="mouse" style="width:100px;height:100px;border:1px solid #000;">hold down mouse button on me!</div>
<script type="text/javascript">
var m = document.getElementById("mouse");
var tmr = 0;
if (m) {
m.onmousedown = startMouseTimer;
m.onmouseup = stopMouseTimer;
}
function startMouseTimer(e) { tmr=new Date(); }
function stopMouseTimer(e) { alert(((new Date()-tmr)/1000)+" seconds"); }
</script>
I'd be interested to know why you think this will be useful?!!
-
grrr, your script doesn't mean much to me but I am sure I can pick it a part with some googling. This would be great for a game or the like.
-
Save that code into a .html file and open it in your browser.
-