Jump to content
Search Community

Scrolltrigger sticks item to top of page on page load in next.js app

Faarda test
Moderator Tag

Go to solution Solved by Faarda,

Recommended Posts

Hi Awesome folks,

I'm trying to use scroll-trigger in a website i'm building with next.js, and I have this weird issue where scroll-trigger fixes the item to the top of the window when the page loads.

It's a simple div with no serious styling, just margins.

I'm currently lazy loading the component using next-dynamic, because, obviously gsap would try to use "window" on load.

Here's what my scroll-trigger intialization looks like

```

const tl = gsap.timeline({

scrollTrigger: {

trigger: container.current,

pin: true,

markers: true,

start: 'top top',

pinSpacing: true,

scrub: true,

end: 'bottom top',

snap: {

snapTo: "labels"

},

anticipatePin: 1

},

});

```

Happy to provide extra details and possibly a codepen link if necessary

Link to comment
Share on other sites

  • Solution

I was trying to reproduce the issue on codesandbox and then i found the actual issue.

I had a page loader that sets the display of the main content of the page to hidden, my guess is when the page loads scrolltrigger cannot actually get the position of the section on the page and so it just fixes it to the top of the page.

Thanks for your help.

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