views:

40

answers:

2

hi, i have mouseover issues sometimes when i move my mouse fast over links it loops for quite a while, is there a way to only loop if mouse is stil over and stop if the mouse is not.

       $('ul.display li').hover(function() {

        $('ul.display li').find('#details').hide(); // hides all deatils div before showing
        $('#light').delay('800').fadeIn("fast"); // shows div that fades out all other content.

if($.cookie("switch_thumb") =="thumb_view" || $.cookie("switch_thumb") =="null"){//checks for cookie set for display type
      $(this).find('#details').delay('900').animate({width:'toggle'}); // grow width
}else{
      $(this).find('#details').delay('900').animate({height:'toggle'}); // grow height
}


      }, function() {

           $('#light').fadeOut("fast"); // dim the light to show all content
        $('ul.display li').find('#details').hide(); //hide all details
   return false; // supposed to stop looping.

      });
A: 

Check out .stop() method

Gaby
This will cause many more issues, not a good idea here.
Nick Craver
@Nick, my understanding is that his problem is the queuing of the multiple hovers.. `stop(true,true)` or `clearQueue()` at the end should take care of that .. i have been known to be wrong, though, before ..
Gaby
@Gaby - This isn't an *obvious* problem, I agree. `.delay()` complicates things, [`.delay()` is a simple `setTimeout()` on a dequeue](http://github.com/jquery/jquery/blob/master/src/queue.js#L75), throwing things really out of wack, because although you stopped the *current* animation, when that timer's done it'll come back and execute whatever's next on the queue from a subsequent hover, really messing with that 900ms delay, e.g. it'll execute much earlier. Short version: don't mix `.stop()` and `.delay()` on the same elements.
Nick Craver
@nick, i see, good point on the `delay()` haven't really used it, and though it was integrated in the animation system ...
Gaby
A: 

I had a similar problem once. stop() can work too, but what I did was to add a class "inmotion" to the element when starting a fade, and remove it when the fade was complete. By ignoring any hover calls when that tag was on, it made sure every action had to finish before the next could begin.

Meekohi
Checkout the [`:animated` selector](http://api.jquery.com/animated-selector/) :)
Nick Craver