How to prevent mouse input or shutdown too many times

I have a piece of code that basically says: if you flip this, then another thing will appear, and if you expand it, it will disappear.

The problem is that if I take out the mouse and roll it too many times, the elements appear / disappear too many times (because I created many events for this by mistake)

my code is as follows:

$('div.accordionContent').mouseenter(function()
{
    $(this).find(".something").animate({left: 0}, 300)}).mouseleave(function() {
    $(this).find(".something").animate({
    left: -200}, 500);;
}); 

How can I say to avoid multiple freezes?

I am using jQuery 1.4.3 if this helps.

+5
source share
5 answers

Instead of avoiding multiple starts, try stopping the animation before starting another.

$('div.accordionContent').mouseenter(function() {
    $(this).find(".something").stop().animate(...)
}); 
+5

, . , ( ) , .

+1

jQuery.animate "queue". false, , . =)

0

,

$('div.accordionContent').bind('mouseenter mouseleave', function(e){

    var $something = $(this).find(".something");

    if(e.type == 'mouseenter'){
        $something.animate({left:0}, {queue:false, duration:300 });
    } else {
        $something.animate({left:-200}, {queue:false, duration:500 });
    }
});
0

:

$('div.accordionContent').mouseenter(function(){
    var div = $(this);
    clearTimeout(window.me);
    window.me = setTimeout(function(){
        div.find(".something").animate({left: 0}, 300)}).mouseleave(function(){
            $(this).find(".something").animate({
            left: -200}, 500); 
        });
    },50);
}); 

, , 50 .

0

All Articles