Jump to content
Search Community

ScrollTrigger wordpress and pin issue

Juan Munoz
Moderator Tag

Go to solution Solved by Rodrigo,

Recommended Posts

Posted

Hi, I'm creating an animation with two lines of images running from left to right and right to left using scrollTrigger. When you scroll until you get to the animation of the images, the section stays fixed and the images move.

 

If you open the page for the first time this effect works correctly, the problems come in two cases:

 

1. If you reload the web and the scroll is not in top 0, the animation is damaged
2. When I resize the window

 

https://juanm225.sg-host.com/

 

I replicated the same animation in a simple html but the animation is not damaged when I reload the page (sometimes it happens)

 

https://juanm225.sg-host.com/html/

 

Thank you very much for any help you can give me.

Posted

Without a minimal demo, it's very difficult to troubleshoot; the issue could be caused by CSS, markup, a third party library, a 3rd party script, etc. Would you please provide a very simple CodePen or Stackblitz that illustrates the issue? 

 

Please don't include your whole project. Just some colored <div> elements and the GSAP code is best. See if you can recreate the issue with as few dependencies as possible. Start minimal and then incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, at least we have a reduced test case which greatly increases your chances of getting a relevant answer.

 

See the Pen aYYOdN by GreenSock (@GreenSock) on CodePen.

that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo

 

Using a framework/library like React, Vue, Next, etc.? 

CodePen isn't always ideal for these tools, so here are some Stackblitz starter templates that you can fork and import the gsap-trial NPM package for using any of the bonus plugins: 

 

Please share the StackBlitz link directly to the file in question (where you've put the GSAP code) so we don't need to hunt through all the files. 

 

Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. 

  • Solution
Posted

Hi Juan,

 

It seems to me that you're using a Wordpress theme that uses Bootstrap under the hood. Bootstrap 5.x by default adds scroll-behavior: smooth to the HTML tag, anything that adds scroll-behavior: smooth to the HTML tag it will result in this behaviour when refreshing the page.  The reason is that adding scroll-behavior: smooth to the HTML tag by default which interferes with the way ScrollTrigger works. That will definitely create a problem when you resize the browser window/tab, since ScrollTrigger scrolls everything to the top in order to run it's calculations again, this is completely necessary and not a problem actually, because we need everything to be at it's natural position in order to calculate the start and end points accurately. The problem with scroll-behavior: smooth is that it creates some sort of transition for the scrolling, so when ScrollTrigger sets the scroll position to 0 it takes sometime to get there and when ScrollTrigger does all the calculations again the current position of the scroll is not 0, so all the calculations are off.

 

What you can do is override that by creating a custom CSS file that has this (or use a current CSS file that you're creating):
 

html {
  scroll-behavior: auto !important;
}

Hopefully this helps

Happy Tweening!

  • Like 1
Posted
22 hours ago, Rodrigo said:

Hi Juan,

 

It seems to me that you're using a Wordpress theme that uses Bootstrap under the hood. Bootstrap 5.x by default adds scroll-behavior: smooth to the HTML tag, anything that adds scroll-behavior: smooth to the HTML tag it will result in this behaviour when refreshing the page.  The reason is that adding scroll-behavior: smooth to the HTML tag by default which interferes with the way ScrollTrigger works. That will definitely create a problem when you resize the browser window/tab, since ScrollTrigger scrolls everything to the top in order to run it's calculations again, this is completely necessary and not a problem actually, because we need everything to be at it's natural position in order to calculate the start and end points accurately. The problem with scroll-behavior: smooth is that it creates some sort of transition for the scrolling, so when ScrollTrigger sets the scroll position to 0 it takes sometime to get there and when ScrollTrigger does all the calculations again the current position of the scroll is not 0, so all the calculations are off.

 

What you can do is override that by creating a custom CSS file that has this (or use a current CSS file that you're creating):
 

html {
  scroll-behavior: auto !important;
}

Hopefully this helps

Happy Tweening!

Hi Rodrigo, thank you very much for your help. Your solution was correct. I was finally able to solve it. I've been changing and changing the code for more than 3 days.

Thank you very much.

  • Like 1

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