Jump to content
Search Community

set() on TimeLineMax

codek test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Hi, I have a problem to understand the "set()" method. This is my html code (extract):


  <path id="nube" opacity="0" ....</path>


and this my js ("nube" is a reference to id="nube" in Angular 5):


let tl = new TimelineMax({ delay: 3, repeat: -1 })

tl.set(nube, { opacity: 1 })
tl.to(nube, 9, { y: '-=30px',x: '+=17px', scale: 2 ,opacity: 0, ease: Linear.easeNone, repeat: -1 }, '')


The problem is that the element "nube" is shown on start but I think that it should be hidden until 3s of delay. Why is showed on start? How can I do the element is shown when "tl" is started (with 3s delay)?


Thanks in advance.

Link to comment
Share on other sites

That's because when a tween is defined it is rendered immediately to the start position, usually only noticed in the case of 'from tweens'. Because you are using set at the start of timeline, it is behaving same.


You can set immediateRender to false on first tween and it will behave as expected. Well and you can use just fromTo tween to same thing.


// To tween
tl.set(".slide", { opacity: 1, immediateRender: false });
tl.to(".slide", 1, { x: 300, opacity: 0 });


// fromTo tween
tl.fromTo(".slide", 1, { opacity: 1, immediateRender: false }, { x: 300, opacity: 0 });


See the Pen Eogozb by Sahil89 (@Sahil89) on CodePen


  • Like 8
Link to comment
Share on other sites

Hello @codek and welcome to the GreenSock Forum!


Keep in mind that you could have also used the GSAP special property autoAlpha instead of opacity. And in your CSS use visibility:hidden. Then your element would not show on load by default and would be animated in with autoAlpha which is part of the CSSPlugin. GSAP autoAlpha is better for performance than using opacity by itself. 


CSSPlugin autoAlpha uses both opacity and visibility: hidden




Identical to opacity except that when the value hits 0 the visibility property will be set to "hidden" in order to improve browser rendering performance and prevent clicks/interactivity on the target. When the value is anything other than 0, visibility will be set to "inherit". It is not set to "visible" in order to honor inheritance (imagine the parent element is hidden - setting the child to visible explicitly would cause it to appear when that's probably not what was intended). And for convenience, if the element's visibility is initially set to "hidden" and opacity is 1, it will assume opacity should also start at 0. This makes it simple to start things out on your page as invisible (set your css visibility:hidden) and then fade them in whenever you want. 


Happy Tweening

  • Like 4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...