补间-无限重复,无需从起始位置开始

时间:2019-05-03 09:58:08

标签: javascript three.js tween greensock tweenmax

我有一个div,我想将它永远移动到向下位置,补间重复-1从元素开始移动的地方开始。我希望它像循环一样继续下去。

var tlMain = new TimelineMax({repeat:0});
tlMain.to(group.position, 2 , {y: '-=10', ease: Power0.easeNone, repeat:-1});

在上面的时间轴上,它的工作方式如下:

Start: 10
1st  : 10
2nd  : 10

所以每次转弯

Start: 10
1st  : 0
2nd  : -10
3rd  : -20

是否可以使用Tween来实现此目的?还是我需要在本机的render方法中进行原始操作?

function render(...args) {
    group.position.y -= 10;

    requestAnimationFrame(render(...args))
}

还是我需要设置一个for循环来无限运行此循环,而不是使用repeat? (有效)

1 个答案:

答案 0 :(得分:1)

这对.repeat()不起作用,因为动画总是从原始位置开始(并且不更改库就无法影响此行为)。对于这种用例,我将手动编写对象的位置动画,如代码示例所示。或者,如果可能,请选择y值低且持续时间长的值。这样,您可以定义一个补间。