Jump to content
Search Community

problem with massive image and horizontal scroll when at the bottom of a page

LSchneiderman test
Moderator Tag

Go to solution Solved by Rodrigo,

Recommended Posts

I'm having a bit of trouble with a massive image and horizontal scroll. It's based on this code: https://easeseas.es/posts/horizontal-scroll-cristobal-balenciaga-museoa/

 

This code works perfectly well on my page when it's the only item on the page. However, when it's at the bottom of a long web page, or even a webpage a few screens long, the horizontal scroll goes abruptly from the beginning of the image to the end with no scrolling in between. 

 

My codepen doesn't seem to reproduce this issue, but you can see it when I put my test page on a server: https://newsinteractive.post-gazette.com/.testLaura/test2.php

 

Can anyone tell me what has gone wrong or how to correct for it?

See the Pen YzRJVBE by lschneiderman (@lschneiderman) on CodePen

Link to comment
Share on other sites

  • Solution

Hi,

 

The problem is that the code is being ran before the image gets to load, so this reports the wrong number:

image.clientWidth - window.innerWidth

Most likely image.clientWidth is zero at that point and that's why your markers are in an odd position:

5AGxsIy.png

As you can see the end point is already passed before the start point is passed, so your animation goes super fast.

 

On top of that using this to set your end point:

end: () => image.clientWidth - window.innerWidth,

Basically tells ScrollTrigger to set your end point to an absolute value in the viewport. Is better to make that relative to the start point like this:

end: () => ("+=" + image.clientWidth - window.innerWidth),

Here is a fork of your codepen:

See the Pen QWJZgZN by GreenSock (@GreenSock) on CodePen

 

Hopefully this helps.

Happy Tweening!

  • Like 1
Link to comment
Share on other sites

  • 5 weeks later...

@RodrigoThat does work, but now I seem to have a weird thing with the pin where as soon as the massive image gets to a certain point on the page (where start hits scroller-end), massiveImage jumps up to its pin spot. I can't get it to just scroll to a certain point and then stick at that point. I'm also unable to reproduce this effect in codepen. I think it might have something to do with anticipatePin. I've tried putting smaller numbers in there (.5, .25) to no avail. Any advice?

Link to comment
Share on other sites

It's pretty tough to troubleshoot without a minimal demo - the issue could be caused by CSS, markup, a third party library, your browser, an external script that's totally unrelated to GSAP, etc. Would you please provide a very simple CodePen or Stackblitz that demonstrates 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 dependancies as possible. If not, incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, then at least we have a reduced test case which greatly increases your chances of getting a relevant answer.

 

Here's a starter CodePen that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo

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

 

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. 

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