【问题标题】:Animate of mouseenter and mouseleave stopmouseenter 和 mouseleave 停止动画
【发布时间】:2013-02-27 05:23:57
【问题描述】:

我正在使用 mouseenter 和 mouseleave 制作动画,问题是如果我在 div 上快速移动鼠标,动画会变得疯狂,就像不停地重复,我该如何解决这个问题,任何一种停下来什么的?

这是我的代码:

    /* Footer Hover */
    function footerhover(){
        var footer = $('#footer')
        footer.bind({
            'mouseenter' : function(){
                footer_animate(200);
                footer_bottom(145);
            },
            'mouseleave' : function(){
                footer_bottom(0);
                footer_animate(40);
            }
        })
    }
    function footer_animate(h){
        $('#footer').animate({
            height: h
        }, 50 );
    }
    function footer_bottom(b){
        $('#footer').animate({
            bottom: b
        }, 300 );
    }

【问题讨论】:

    标签: javascript jquery html


    【解决方案1】:

    在开始一个新动画之前,最好使用 jQuery 的 stop 函数停止当前动画,否则它们会堆积起来,一遍又一遍地触发。因此,每次为页脚设置动画时,请先停止它。

    $('#footer').stop().animate({});
    

    【讨论】:

    • 将 .stop 应用于两个动画会使其从一开始就停止它......所以它根本不起作用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多