www.webdeveloper.com
Results 1 to 2 of 2

Thread: Firing an event after a pause, but cancel if there's activity

  1. #1
    Join Date
    Dec 2002
    Location
    charlotte, nc
    Posts
    50

    Firing an event after a pause, but cancel if there's activity

    Hello. I'd like to fire a javascript event 1000 milliseconds after an event, but I'd like to CANCEL that event if there's activity again. So a simple setTimeout wont work because it'll fire regardless. I have the following but it kinda works and kinda doesn't.

    showMoveControls is triggered on mouseover and hideMoveControls is triggered on mouseout.

    As you can probably tell, I'm showing additional menu options if a user hovers over a toolbar for a few moments. But if they casually are just mousing up to the toolbar or over it without pausing, then I don't want those options to show.

    Any help is appreciated.

    Code:
    var killFlag=null;
    function showMoveControls() {
         killFlag=null;
         setTimeout("doOpenMoveControls()", 1000)
    }
    function doOpenMoveControls() {
         if (!killFlag) {
             $('move_controls').show();
        }
    }
    function hideMoveControls() {
         killFlag=1;
         $('move_controls').hide();
    }
    Last edited by dep; 04-30-2009 at 12:13 PM.

  2. #2
    Join Date
    Jun 2007
    Posts
    667
    This should do it:
    Code:
    var timer = null;
    function showMoveControls() {
       clearTimeout( timer );
       timer = setTimeout("doOpenMoveControls()", 1000);
    }
    function doOpenMoveControls() {
    
             $('move_controls').show();
    
    }
    function hideMoveControls() {
         clearTimeout( timer );
         $('move_controls').hide();
    }

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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