Jump to content
Search Community

Properties update before animation occurs

al 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

I am doing some basic animations, and I setup all of my Timelines and Tweens before hand in anticipation of certain UI events.  However, even though the animations don't run until later, properties are being set immediately on the elements.

 

For example, i have a div that i want to show when someone  clicks a button.  Even though I havent called the play() method on the animation, all of the properties are set to their target state (ie. opacity: 1).

 

Am I doing something wrong?

 

Thanks,

Andrew

Link to comment
Share on other sites

Hi and welcome to the GreenSock forums.

It sounds like yes, you are doing something improper but its impossible to tell without seeing an example. 

 

The only thing I would suggest is that perhaps you need to pause each animation when it is created.

TweenLite.to(something, 1, {left:200, paused:true});

The best thing to do is take a codepen example like this one: http://codepen.io/GreenSock/pen/BLajh and fork it and edit it to replicate your issue with as little code as possible. That way the support team can see exactly what is happening and report back to you with a fixed version.

Link to comment
Share on other sites

Hi and welcome to the Greensock forums.

 

By any chance are you using from() instances in your timeline. If you are, that's standard behaviour. From instances take the target values indicated in the tween vars and apply them immediately to the element and when played take the element from those values to the values the element had when the DOM was rendered.

 

For example if in the stylesheet you created a class with opacity:0 and tween the element's opacity with a from instance with a value of 1, the element starts with a value of 1 and goes to 0:

<style>
.class1
{
  opacity:0
}
</style>

<body>
<div id="element" class="class1"></div>

<script>
var element = document.getElementById('element')
    tl = new TimelineLite({paused:true});

tl
  .from(element, 1, {opacity:1})
  .play();

</script>
</body>

In order to respect the element's style you can add immediateRender:false, that will apply the from value when the animation starts:

tl
  .from(element, 1, {opacity:1, immediateRender:false})
  .play();

If this is not your scenario, please create a reduced sample including just the code that's causing the issue in jsfiddle or codepen to get a better look.

 

Rodrigo.

  • Like 1
Link to comment
Share on other sites

Thank you all for the replies.  I am indeed using Tweenlite.from in some of my timelines.  

 

I paused the timeline as a whole but that was not helping.  immediateRender: false seemed to do the trick.

 

Thanks alot.  Next time I will post a sample on code pen.

 

On a side note, I am creating a rental listings SPA using google maps and greensock for all of the animations.  Is anyone interested in trying it out before I go live?

 

Andrew

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...