Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Feb 2011
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    {Jquery} On mousedown disable timer, Possible?

    Hi i have a timer which is set to execute a function every 3 seconds, id like to know if it's possible to diable the timer function every time the mousBtn is held (mousedown), and on mouseup enable the timer again, and how can i do this?

    Code:
    var timerFunc = setInterval( loadPos, 3000 );

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by sven_paul View Post
    Hi i have a timer which is set to execute a function every 3 seconds, id like to know if it's possible to diable the timer function every time the mousBtn is held (mousedown), and on mouseup enable the timer again, and how can i do this?

    Code:
    var timerFunc = setInterval( loadPos, 3000 );
    not tested:
    Code:
    var timer = null;
    $('button selector').mouseup(function(){
       timer = setInterval( loadPos, 3000 );
    });
    $('button selector').mousedown(function(){
       if(timer){
          clearInterval(timer);
       }
    });
    best regards


  •  

    Posting Permissions

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