Jump to content
Search Community

replaceChild and TimelineMax

benoit 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

Hello @benoit

 

Can you please give us more details on what exactly you are trying to do. Its confusing since in your code it keeps replacing a child with the same exact <div> element with the same class and the same text value. Any reason why your doing that? All that will do is cause some layout thrashing of constantly trying to animate something that is affecting layout calculations for the same element. Also keep in mind that when animating transforms you should set the CSS position to absolute so it doesn't cause a reflow of the layout in the document flow.

 

Any additional information will be helpful in letting us know how we can help you :)

 

Resources:

https://www.impressivewebs.com/absolute-position-css/

https://www.w3.org/TR/css-position-3/#abs-pos

 

  • Like 2
Link to comment
Share on other sites

You could just replace a child element and animate the container(s). 

 

Or you could write a function that creates the "tl" timeline again, but of course with the new element in place. Sorta like:

var tl = animateBoxes(); 
function animateBoxes() {
  var newTL = new TimelineLite({onComplete:load});
  newTL.to('.item',1,{x:300});
  return newTL;
}

function load() {
  tl.pause(0).kill();
  //...do whatever swapping/replacement here...
  tl = animateBoxes();
}

 

Does that answer your question?

  • Like 4
Link to comment
Share on other sites

Sorry, I forgot to add the "tl = " in there. Edited.

var tl = animateBoxes(); 
function animateBoxes() {
  var newTL = new TimelineLite({onComplete:load});
  newTL.to('.item',1,{x:300});
  return newTL;
}

function load() {
  tl.pause(0).kill();
  //...do whatever swapping/replacement here...
  tl = animateBoxes();
}

 

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