www.webdeveloper.com
Results 1 to 2 of 2

Thread: Constantly rolling over button

  1. #1

    Post Constantly rolling over button

    Hi All,

    I need to javascript a button so that when moused over and the mouse button is held down, the action constantly repeats until the mouse button is released.

    I need this to keep incrementing a value until the customers chosen value is reached when the mouse button is released. Also a decrementing button in case they go too far.

    Cheers

  2. #2
    Join Date
    Mar 2009
    Posts
    467
    You might try something like this:

    /
    Code:
    /given persistent outside variables which are in the same scope
    //as this function, and a function where xtimer is just a holder, and
    // val is the value to be incremented
    
    myButtonRef.onmousedown = function(){
    	var z =function(){
                              val = val + 1;
    			  xtimer = setTimeout(z,200);
    	};
    	z();
        }
     myButtonRef.onmouseup = function(){clearTimeout(xtimer);};
    Change the time interval to suit yourself.
    Last edited by Tcobb; 05-01-2013 at 11:21 PM. Reason: typo in code

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles