【问题标题】:Endless animation function that receives a parameter on 'hover' event接收“悬停”事件参数的无尽动画功能
【发布时间】:2016-05-31 13:34:31
【问题描述】:

这个想法是在光标位于 div 上时执行动画。我已经这样做了,但现在带有动画的函数接收一个参数,如果我添加参数,页面就会爆炸。如果没有最后一次调用该函数,代码不会使页面崩溃。 请检查我的代码:

function OnHover() {
    function Animation(obj) {
        obj.stop().animate({ top: '20px' }, 600).animate({ top: '0px' }, 600, Animation(obj));
}

    $('#infobox').hover(
        function(event) {
            $circle = $(event.target).children().first();
            Animation($circle);
        }, 
        function(event) {
            $circle = $(event.target).children();
            $circle.stop();
        }
    );
}

【问题讨论】:

    标签: javascript jquery hover jquery-animate


    【解决方案1】:

    我已经使用了这个解决方法:

    $target = undefined;
    $("#wrapper .infobox").mouseenter(event, function animate() {
                    if (typeof $target == 'undefined')
                        $target = $(event.target).children();
    
                    $target.animate({ marginTop: "+=40px" }, 600);
                    $target.animate({ marginTop: "-=40px" }, 600, animate);
                }
            );
            $("#wrapper .infobox").mouseleave(function() {
                    $target.stop(true, false).animate({ marginTop: '20px'}, 300);
                    $target = undefined;
                }
            );
    

    【讨论】:

      猜你喜欢
      • 2015-02-26
      • 1970-01-01
      • 2020-12-01
      • 2020-09-25
      • 2012-06-01
      • 2015-03-17
      • 2014-08-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多