Jump to content
Search Community

Viewport jumps when content height flips

Bartholomey test
Moderator Tag

Go to solution Solved by Bartholomey,

Recommended Posts

Hello,

I have a column of cards. When any of the cards is clicked, it expands using Flip plugin and changes its height and previously opened cards close. But there is an issue - if I try to open card below any other opened card, the viewport jumps as you can see on the video.
I don't use any scroll manipulation, only the Flip plugin.


I recorded what is exactly happening https://streamable.com/fwowm3. If it does not help please let me know and I will try to create a demo.

EDIT: It seems like when there is enough room in the viewport for the full height of expanded card, the issue is gone, otherwise it glitches like that.

EDIT 2: It does not glitch as long as the final state is that I can see currently clicked card fully expanded and at least few pixels of the above card in viewport.

EDIT 3: Looks like adding this code to the card flip animation kind of helps, but the behavior has to be set to "instant" as "smooth" is too slow. However this approach does not look nice as the card instantly snaps to the top of viewport.
 

onUpdate: () => {
    // Check if the top of the card is in view during the animation
    const rect = recipeCard.getBoundingClientRect();
    if (rect.top < 0 || rect.top > window.innerHeight) {
        const scrollOffset = rect.top - 20; // Adjust 20 pixels of space above
        window.scrollBy({ top: scrollOffset, behavior: "instant" });
    }
},
Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

  • Solution

I managed to make this work by keeping the the same space between top viewport and top of the card while animation is in flight. However it does not look as nice as i though (and probably not good for performance as it has to update the viewport position on every frame) so I decided to close any previously opened cards when its fully hidden outside of viewport on scroll which seems to be better UX.

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