Jump to content
Search Community

GSAP target .Service1(class) not found.

s.kubota test
Moderator Tag

Recommended Posts

 

I want to scroll a part of the screen horizontally with the scroll trigger, but it doesn't work with a warning.

It is displayed that the target cannot be found.
Is there a solution?

 

I also wrote gsap.registerPlugin (ScrollTrigger), but I get a warning.

 

 

スクリーンショット 2022-04-13 13.40.30.png

Link to comment
Share on other sites

It's very difficult to troubleshoot without a minimal demo, but my guess is that you are trying to animate elements that don't exist yet because you put your script in the <head>, so when the browser executes it, the <body> hasn't even been parsed yet so the elements aren't parsed. Try either moving your <script> tags to the bottom of the </body> or you could execute your code in the onload or in a DOMContentLoaded event handler. 

 

Good luck!

  • Like 1
Link to comment
Share on other sites

It's generally okay to load the library in the <head> but I strongly prefer to load all scripts just before the closing </body> tag so that:

  1. It allows the browser to parse/display the content faster
  2. It ensures that the elements you want to animate actually exist. 

So I personally would recommend moving all of your <script> tags down there. But again, that's not mandatory - you could just use an onload to delay the execution of your animation code until things are loaded. The whole point here is to wait to animate things until the page has loaded and the elements exist. 

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