Jump to content
Search Community

GSAP browser error message

brandpirate test
Moderator Tag

Recommended Posts

Hello everyone!

 

I am using gsap on Wordpress.

 

Not every single page contains an animation of couse, so I have the problem, that on a single page of an entire homepage-project, where I dont use all gsap animations, the browser tells me this warning. 

 

1279412162_Bildschirmfoto2021-05-03um19_17_28.png.84bc6b45b2dbe842261523df4d24a141.png

 

It tells me, that an ID that I used for a animation on one site, can obviously not be found on the current site.

 

1535367925_Bildschirmfoto2021-05-03um19_20_20.thumb.png.7e39cbc2304aa92e9d82e9cae36c78fa.png

 

But how can I avoid this error message?

 

Thanks,

 

Manu

Link to comment
Share on other sites

Hi @brandpirate,

 

One thing to note is those are not errors, those are console warnings. It's perfectly fine to receive them. But, it's better not to. There are quite a few ways to go about this ... ultimately what you want to do is not run your GSAP code on pages where it's not called for.

 

Seeing as this is WordPress, I assume jQuery is loaded. You can simply check to see if an element is on the page first

 

if( $('#home-headline-h1').length ){
   gsap.from('#home-headline-h1, #home-headline-short', {delay: 0, duration: 2, opacity: 0, x: -50});
}

Hope this helps.

 

Shaun

  • Like 1
Link to comment
Share on other sites

10 minutes ago, Shaun Gorneau said:

There are quite a few ways to go about this ... ultimately what you want to do is not run your GSAP code on pages where it's not called for.

 

Sorry, WordPress n00b here. Isn't there a way to not load the file to begin with?

 

Link to comment
Share on other sites

10 minutes ago, OSUblake said:

Isn't there a way to not load the file to begin with?

 With WordPress (and Drupal and pretty much any CMS) there are a number of ways you can include JS on specific pages

  • You can choose to preprocess on any conditions and load JS files
  • You can use PHP logic in a template file to determine when to load a JS file
  • You can include the <script> call on the page itself, but that could be troublesome from a CMS standpoint

Unfortunately, it's easier to call script and css files at the config level of the theme and put the logic within the script.

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