.tweenFromTo()

优质
小牛编辑
128浏览
2023-12-01

.tweenFromTo( fromPosition:*, toPosition:*, vars:Object ) : TweenLite
创建一个线性动画,将时间轴从某时间或标签播放到指定时间或标签,然后停止。要使TimelineMax播放到"myLabel2"标签,只需执行以下操作:

var tl = new TimelineMax(); 
tl.add( myTimeline.tweenFromTo("myLabel1", "myLabel2") );
tl.add( myTimeline.tweenFromTo("myLabel2", 0) );

如果要对动画进行高级控制,只需将参数传入vars即可,如

myTimeline.tweenFromTo(0, 5, {onComplete:myFunction, onCompleteParams:[myTimeline], ease:Strong.easeOut});

.tweenFromTo()适用于TimelineMax

.tweenFromTo()的参数

参数类型必填说明
fromPosition*动画的起点时间点或者label标记
toPosition*动画的终点时间点或者label标记
varsObject传入动画的参数,如onComplete, ease, delay或其他TweenLite的可用选项。onInit是唯一不可用的属性

.tweenFromTo() 示例


.box {
  width:50px;
  height:50px;
  position:relative;
  border-radius:6px;
  margin-top:4px;
}
.green{
  background-color:#6fb936;
}
.orange {
  background-color:#f38630;
}
.grey {
  background-color:#989898;
}
var tm = new TimelineMax();
tm.to('.green', 2, {x:200}) 
  .to('.grey', 2, {x:300}) 
  .to('.orange', 2, {x:400})
  .tweenFromTo(1, 4.5)

.tweenFromTo()返回值

返回一个TweenLite实例。

.tweenFromTo()的补充说明

tweenFromTo()只是创建一个TweenLite实例,该实例会暂停时间轴,然后对时间轴的time()进行动画。因此你可以单独引用或储存这个动画,还可以随时kill()
请注意,tweenFromTo()不会影响时间轴的reversed状态,因此,如果你的时间轴正常定向(未反转)并且你动画到当前时间之前的时间/标签,它将显示为倒退但reversed状态不会更改为true。
tweenFromTo()在动画之前暂停时间轴,并且在完成后它不会自动恢复。如果你需要恢复时间轴播放,可以使用onComplete来调用时间轴的resume()方法。

与全部from类型的方法类似,immediateRender(立即渲染)默认为true,意思是立即跳转到动画起点。你可以在vars中设置immediateRender:false,如.tweenFromTo(1, 5, {immediateRender:false})