Share Posted September 7, 2018 Hello. I'm working on an animated display ad which uses dynamic content pulled in from a feed using JavaScript. I have an unordered list that is populated with content dynamically with JavaScript, the list could contain a variable amount of list items at varying lengths. When I try an animate this list with GreenSock (revealing it by animating the height from 0px) it animates the list based on the content not being there. How can I make GreenSock see the content that gets dynamically generated with JavaScript? Hopefully this makes sense, it's difficult to create a CodePen on this one since it links to external sources etc. Cheers Link to comment Share on other sites More sharing options...
Share Posted September 7, 2018 Hi cbg, Our beloved moderator @Jonathan taught me long ago: // wait until DOM is ready document.addEventListener("DOMContentLoaded", function(event) { window.addEventListener("load", function(){ // place your code here }); }); That will cause all the code nested inside the event listeners to wait until the DOM is ready and all assets are loaded. You should then be able to tween your elements as you desire. 3 Link to comment Share on other sites More sharing options...
Author Share Posted September 7, 2018 Thank you! Do you know how I can make the following run, only if the image exists in the DOM? .to ("#image2", 0.5, {opacity:0, delay: 3}) Link to comment Share on other sites More sharing options...
Share Posted September 7, 2018 Would it be a conditional? Sometimes being there, sometimes not? If so, wrap the line into a if() statement. // Somewhere at the start const img2 = document.querySelector("#image2") // Timeline setup const tl = new TimelineMax() tl.to( "image1", 1, { x: 100 } ) if( img2 ) { tl.to( img2, 1, { autoAlpha: 0 } ) } tl.to( "image3", 1, { autoAlpha: 0 } ) Also, better than adding a delay parameter to a tween in a timeline is to use the position parameter: // not wrong .to ("#image2", 0.5, {opacity:0, delay: 3}) // better .to ("#image2", 0.5, {opacity:0}, "+=3") 5 Link to comment Share on other sites More sharing options...
Author Share Posted December 12, 2018 I just realised a new problem I'm having is very similar to this one. I've tried implementing the DOM ready fix but in this instance the heights still aren't being calculated correctly? https://greensock.com/forums/topic/19539-loading-gsap-after-javascript-dynamically-generated-elements-have-loaded/?tab=comments#comment-90744 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now