开发者

jQuery looping my fadeIn/fadeOut

I've done some easy .hover(function() statement in jQuery. When i hover over a text i simply want a #div.fadeIn, and on non-hover fadeOut. It works. But it's just if i spam the text-trigger with hover and un-hoverring really quickly and then 开发者_Go百科stop the animation begin to give a blinking effect. It just kind of loops, really annoying!


There are a few easy ways to fix this, but this one should provide a nice effect for what you want:

$("#yourtrigger").hover(function(){
    $("#div").stop(true).fadeTo( "fast", 1.0);
}, function(){
    $("#div").fadeOut( "fast" );
});

Its important not to use fadeIn with this method as it will stop fading after a while because of how jQuery tracks what it should "fade in to".


If you have something like this:

$('#your_div').action1().action2();

Change it to:

$('#your_div').action1(miliseconds, function() {
   $(this).action2(); 
});

You can even, with v1.4, add the delay() call like this.

$('your_div').action1().delay(miliseconds).action2();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜