Share Posted May 22, 2018 I'd like to see if there's a way to load GSAP through JavaScript and then create a timeline after it's loaded and ready. I tried to use fetch + then to achieve this, but I think there's something I'm doing wrong here. fetch('https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.3/TweenMax.min.js') .then(function() { var tl = new TimelineMax({repeat: -1}); tl.to("#square", 1, {x: 300}) .to("#square", 1, {x: 0}) ; }); Th error I'm receiving: Uncaught (in promise) ReferenceError: TimelineMax is not defined I'm not sure if this is just a JavaScript error or an error with how GSAP needs to be loaded. See the Pen VxNKyz by anon (@anon) on CodePen Link to comment Share on other sites More sharing options...
Share Posted May 23, 2018 I don't have time to look into the specifics, but I believe the problem is that you're not actually doing anything with the TweenMax file that was fetched. In other words, you've gotta put it into a <script> element and dynamically push it into the browser so that it understands it as a JavaScript resource. See what I mean? 1 Link to comment Share on other sites More sharing options...
Author Share Posted May 23, 2018 6 hours ago, GreenSock said: I don't have time to look into the specifics, but I believe the problem is that you're not actually doing anything with the TweenMax file that was fetched. In other words, you've gotta put it into a <script> element and dynamically push it into the browser so that it understands it as a JavaScript resource. See what I mean? I think I know what you mean. Not sure how to do this off the top of my head but will look into it. Basically the script is loaded, but not executed? Link to comment Share on other sites More sharing options...
Share Posted May 23, 2018 3 minutes ago, Fakebook said: I think I know what you mean. Not sure how to do this off the top of my head but will look into it. Basically the script is loaded, but not executed? Yep, that's the basic idea. It's just a long string as far as the browser is concerned. It has no idea that you want it to execute it as JavaScript until you properly inject it into the DOM. 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