SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2007
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up 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

  2. #2
    SitePoint Addict
    Join Date
    Apr 2001
    Location
    Devon, UK
    Posts
    333
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?!!

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2007
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  4. #4
    SitePoint Addict
    Join Date
    Apr 2001
    Location
    Devon, UK
    Posts
    333
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Save that code into a .html file and open it in your browser.

  5. #5
    SitePoint Zealot
    Join Date
    Mar 2007
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hehehe. Thanks again


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •