Bryan.lwj Posted September 4, 2022 Share Posted September 4, 2022 I have no idea why gsap is not working. it display GSAP target .box not found. in console this is my code: <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.1/gsap.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.1/ScrollTrigger.min.js"></script> </head> <body> <script> gsap.to(".box",{ x:500, duration: 3 }) </script> <style> .background{ background: white; width: 100%; height: 100vh; } .box{ width: 300px; height: 300px; background-color: black; } </style> <div class="background"> <div class="box"></div> </div> </body> Link to comment Share on other sites More sharing options...
Solution Carl Posted September 4, 2022 Solution Share Posted September 4, 2022 Hi and welcome to the GreenSock forums. Your gsap code is running BEFORE box is available in the DOM. Move your code to the bottom. Usually best right before the closing </body> tag <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.1/gsap.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.1/ScrollTrigger.min.js"></script> <style> .background{ background: white; width: 100%; height: 100vh; } .box{ width: 300px; height: 300px; background-color: black; } </style> <div class="background"> <div class="box"></div> </div> <script> gsap.to(".box",{ x:500, duration: 3 }) </script> Check out my free GSAP beginner's course. I think you'll find it helpful https://www.creativecodingclub.com/courses/gsap-3-express 1 Link to comment Share on other sites More sharing options...
Bryan.lwj Posted September 5, 2022 Author Share Posted September 5, 2022 Thank you for your help. Thank you so much 1 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