Fading in different items and different times using Greensock Tween

房东的猫 提交于 2019-12-23 04:15:49

问题


I am really new with GSAP and I think it is amazing. However I cannot work out how to fade in these items separately.

1st one (this is fine) for the 2nd wish to fade in at a certain time and 3rd at a certain time.

JavaScript:

function startFinalAnimation(){
    var fa = new TimelineLite();
    fa.to(finalAvatar, 2, {scale: 0.45, delay: 0, opacity: 1, transformOrigin:"-3% 8.8%"});
    fa.to(finalContent, 4, {delay: 0, opacity: 1});
    fa.to(logo, 5, {delay: 0, opacity: 1});
}

回答1:


TimelineLite's .to() method syntax is as follows:

timeline.to(target, duration, vars, position);

This fourth position parameter is something you can use to exactly position wherever you want your tween to appear. So you could, for example, do:

function startFinalAnimation(){
    var fa = new TimelineLite();
    fa.to(finalAvatar, 2, { scale: 0.45, opacity: 1, transformOrigin:"-3% 8.8%" });
    fa.to(finalContent, 4, { opacity: 1 }, '-=1');
    fa.to(logo, 5, { opacity: 1 }, '-=2');
}

Here, -=1 (and -=2) basically tell that the animation should be added at an overlap of 1 second onto the previous animation's end, instead of the default which is to append at the very end of previously added animation.

There are many ways a position can be provided. Above, I used -=. Other options are (taken from the link provided below):

  • at an absolute time (1).
  • relative to the end of a timeline allowing for gaps ("+=1") or overlaps ("-=1").
  • at a label ("someLabel").
  • relative to a label ("someLabel+=1").

Read more about the position parameter here: Timeline Tip: Understanding the Position Parameter.



来源:https://stackoverflow.com/questions/32143458/fading-in-different-items-and-different-times-using-greensock-tween

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!