使用 live() 触发 jQuery 动画

发布于 2024-09-11 22:28:50 字数 202 浏览 1 评论 0原文

我有一个 jQuery 动画无法正常工作。我认为问题来自于动态元素部分。

是否可以使用 animate() 调用 live() 方法?

这是我到目前为止所做的:

$(".tls").animate({"left": "-=50px"}, "slow");

I have a jQuery animation that is not working. I think the porblem comes from the parts that are the dynamic elements.

Is it possible to call the live() method with animate()?

Here's what I've go so far:

$(".tls").animate({"left": "-=50px"}, "slow");

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

终难愈 2024-09-18 22:28:50

我假设你有某种动画触发器?

您提供的代码行将在代码中到达该代码行时运行动画 - 您似乎想要的是将动画绑定到元素,然后稍后执行它。

尝试,例如,

$('.tls').on('click', function(ev) { 
    $(this).animate({left: '-=50px'}, 'slow'}); 
    // Add any necessary event handling here, for example
    ev.preventDefault();
    ev.stopPropagation();
});

I assume you have some kind of trigger for the animation?

The code line you supplied will run the animation whenever the code line is reached in the code - what it seems you want, is to bind an animation to an element, and execute it later.

Try, for example,

$('.tls').on('click', function(ev) { 
    $(this).animate({left: '-=50px'}, 'slow'}); 
    // Add any necessary event handling here, for example
    ev.preventDefault();
    ev.stopPropagation();
});
淡墨 2024-09-18 22:28:50

LiveQuery 非常适合处理动态元素。

http://docs.jquery.com/Plugins/livequery

LiveQuery is pretty good for dealing with dynamic elements.

http://docs.jquery.com/Plugins/livequery

看海 2024-09-18 22:28:50

你如何进行实时通话?也许你应该使用委托: http://api.jquery.com/delegate/

How are you making the live call? Maybe you should use delegate instead: http://api.jquery.com/delegate/

焚却相思 2024-09-18 22:28:50

有同样的问题。需要在没有触发器的情况下进行实时和动画处理。我写了一些解决办法。我用递归函数修复了它。这是我的例子:

    $("#drops").html('<div class="drop-item item"></div>');

    adddrop();

    function adddrop() {
        $(".drop-item").animate({
            top: "+=90%"
        },2500,"easeInQuad", function() {
            if (parseInt($(".drop-item").css('left')) == parseInt($("#paddle").css('left'))) 
            {
                $("#drops").html('<div class="drop-item item"></div>');

                adddrop();
            } 
            else
            {
                alert('fail');
            } 
        });
    }

希望我能帮忙。

Had the same problem. Needed live and animate without an trigger. I wrote a little work around. I fixed it with a recursive function. Here is my example:

    $("#drops").html('<div class="drop-item item"></div>');

    adddrop();

    function adddrop() {
        $(".drop-item").animate({
            top: "+=90%"
        },2500,"easeInQuad", function() {
            if (parseInt($(".drop-item").css('left')) == parseInt($("#paddle").css('left'))) 
            {
                $("#drops").html('<div class="drop-item item"></div>');

                adddrop();
            } 
            else
            {
                alert('fail');
            } 
        });
    }

Hope I could help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文