jQuery on hover animation fires multiple times

混江龙づ霸主 提交于 2019-12-06 08:52:45

You must use the stop() function.

jQuery(function($) {

    $("#searchWrapper").hover(
        function () {
            $(".searchLinks").stop(true,true).fadeIn( 500 );
        },
        function () {
            $(".searchLinks").stop(true,true).fadeOut( 500 );
        }
    );

});

Also, reduce the margin of .searchLinks if you don't want to see it fadeOut when the mouse is between it and it's parent. (padding-top instead of top)

(see http://jsfiddle.net/421g2cdh/11/)

Every time you are hovering the element you must stop the currently-running animation on the matched elements.

Use stop()

Try:

 jQuery(function($) {

        $("#searchWrapper").hover(
            function () {
                $(".searchLinks").stop().fadeIn( 500 );
            },
            function () {
                $(".searchLinks").stop().fadeOut( 500 );
            }
        );

    });

DEMO

Use stop() and you could use in/out hover method handler as it:

jQuery(function ($) {
    $("#searchWrapper").hover(
    function () {
        $(".searchLinks").stop().fadeToggle(500);
    });
});

jsFiddle

fadeToggle()

None of the above worked for me but I found a solution that only fires once using .unbind():

$("#sidebar").unbind().on('mouseenter', function() {
    console.log('mouse entered sidebar');
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!