开发者

Stop fadeToggle() from building up

开发者 https://www.devze.com 2023-02-05 05:11 出处:网络
When I hover over what I want fading in and out too many times, then it keeps repeating itself. Even when I stop hovering it. How can I stop this?

When I hover over what I want fading in and out too many times, then it keeps repeating itself. Even when I stop hovering it. How can I stop this?

$(".featured").hover(function(){
    $(this).f开发者_运维问答ind("h3").fadeToggle(800);
   });


You need to call .stop()

$(this).find("h3").stop(true, true).fadeToggle(800);

Parameters indicate: clearQueue, jumpToEnd
This will almost immediately stop the current animation. To have a more smooth stopping, you should call .stop(true, false)

Another way I can think of is to check whether the element is animated or not:

$(".featured").hover(function(){
    var $h3 = $(this).find('h3');

    if(!$h3.is(':animated') ) 
        $h3.fadeToggle(800);
});

Reference: .stop(), :animated selector

0

精彩评论

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