【问题标题】:jQuery animation more smoother?jQuery 动画更流畅?
【发布时间】:2011-11-01 08:52:44
【问题描述】:

问题不断演变

  1. 这个随机浮动脚本只允许进行步进移动 就像先到左边然后到顶部一样,但在完美的情况下它会在两者之间
  2. 不够流畅

我也尝试过使用缓动插件

代码在这里:

function ran(min, max)
{
    return Math.floor(Math.random() * (max - min + 1)) + min;
}
function moveIt()
{
    $(".circle").each(function() {
        x = ran(-3, 3);
        y = ran(-3, 3);
        pos = $(this).position();
        nowX = pos.left + x;
        nowY = pos.top + y;
        $(this).animate({"left": nowX}, {queue:false, duration:400, easing: 'linear'});
        $(this).animate({"top":  nowY}, {queue:false, duration:400, easing: 'linear'});
    });
}
setInterval(moveIt, 400);

【问题讨论】:

  • 所以我们知道您的问题,现在您的问题是什么?
  • 如何摆脱之字形运动.....它很小......但很明显
  • Smoother Jquery Animation 的可能重复项

标签: jquery jquery-animate setinterval smooth motion


【解决方案1】:

用下面更新了你的函数。

1) 将您的 2 个 animate() 调用合并到 1 个中

2) 使用animate() 自己的success 回调替换setInterval() 以递归调用。

3) 使用delay() 方法替换setInterval()

4) 尝试通过减少每个循环之间的延迟来“平滑”动画。 (这是你设置的400)

http://jsfiddle.net/6kxts/

【讨论】:

    猜你喜欢
    • 2011-09-13
    • 2015-04-22
    • 2018-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多