Question

let me explain my problem. I have a mouseout event assigned to a div tag with an id of calendar. Now when this handler is called (when the mouse is not over the calendar div), i want to wait 2 seconds, then see if the mouse is still not over the calendar div. If the mouse i still out then do a function, if not then do nothing.

I use the prototype javascript library. My code is as follows:

$('calendar').observe('mouseout', function (event){ 
    setTimeout(/* call this event again */, 2000);
}

Thanks

Was it helpful?

Solution

$('calendar').observe('mouseout', function(e) {
   myTimeout = setTimeout(function() { /* stuff to do after 2 secs */, 2000);
});

$('calendar').observe('mouseover', function(e) {
   if(myTimeout) window.clearTimeout(myTimeout);
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top