Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevents a possible scrollbar related layout shift during zoom in/out #12

Merged
merged 2 commits into from
Jun 24, 2024

Conversation

millette
Copy link
Contributor

@millette millette commented Jun 7, 2024

Force vertical scrollbar on body.

Why

Currently, the page reflows a little bit when zooming since the vertical scrollbar disappears, making the page larger.

How

Forcing the scrollbar means the page doesn't get wider (even a little bit) when zooming.

Force vertical scrollbar on body.

Currently, the page reflows a little bit when zooming since the vertical scrollbar disappears, making the page larger.

Forcing the scrollbar means the page doesn't get wider (even a little bit) when zooming.
Copy link

vercel bot commented Jun 7, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
starlight-image-zoom ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 24, 2024 9:16am

@HiDeoo
Copy link
Owner

HiDeoo commented Jun 18, 2024

Thanks for your contribution 🙌

Sorry for the delay in reviewing your code, it looks like this PR totally slipped through my notifications.

I tested the change on macOS with various scrollbar configurations (always visible, visible when scrolling, etc.) and it looks like the approach used in the PR does not prevent the issue in all cases. It also has the side effect of making the scrollbar always visible, even when not needed which is not ideal.

I think a better approach would be to stop enforcing an hidden overflow on the body element through CSS and instead, use JavaScript to do the same when opening the dialog while also constraining the body's width. When the dialog is closed, the overflow and width should be reset to their original values.

I'll investigate a bit more later today and test on more devices to make sure the solution works in all cases, but if it does, I'll update the PR with the new approach.

@millette
Copy link
Contributor Author

It also has the side effect of making the scrollbar always visible, even when not needed

It's probably a personal preference, but I don't like when layouts change in width for shorter or longer pages. Forcing the scrollbar means pages all have the same width so it's predictable. That was my intent at least.

Copy link
Owner

@HiDeoo HiDeoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've implemented the new approach I mentioned earlier which should prevent layout shifts during zoom in/out no matter of the scrollbar user preferences. I've tested it on macOS and Windows and on most of the browsers and it seems to work fine.

Thanks for the contribution and patience 🙌

@HiDeoo HiDeoo changed the title Update custom.css fix: prevents a possible scrollbar related layout shift during zoom in/out Jun 24, 2024
@HiDeoo HiDeoo merged commit 8529c7c into HiDeoo:main Jun 24, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants