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

Can we fix "Scroll bar width calculated incorrectly" issue from original BSL lib? #16

Closed
krutoo opened this issue Jul 31, 2023 · 4 comments

Comments

@krutoo
Copy link

krutoo commented Jul 31, 2023

Hi, i describe problem with original BSL library here:
willmcpo/body-scroll-lock#239

Can we fix that algorithm in this body-scroll-lock-upgrade?

@ialse
Copy link

ialse commented Aug 1, 2023

I'll add that the width needs to be calculated via getComputedStyle since it's different from clientWidth. Therefore, there is a small content shift.

That is, instead of

const scrollBarGap = window.innerWidth - document.documentElement.clientWidth;

need to

const scrollBarGap = window.innerWidth - document.documentElement.getBoundingClientRect().width

As a rule, this gives a fractional number, due to which there is a minimum content shift

UPD:
Checked in Chrome, unfortunately did not work. The scroll width was calculated as 16.333, but a small shift still remained. Empirically, I calculated that the correct value is 16.666, then there is no shift. Apparently, there are some nuances of browser rendering

UPD2:

For myself, I solved the problem by setting the width of the scrollbar to exactly 16 px . Unfortunately, this is only possible for webkit browsers. But for this I had to redefine all the properties of the scrollbar:

https://stackoverflow.com/questions/9060421/css3-how-to-restore-webkit-scrollbar-property-to-the-default-scroll-bar

01-08-2023.134539.mp4

width

@rick-liruixin
Copy link
Owner

Yes, I will fix this feature in my recent free time @krutoo @ialse

@krutoo
Copy link
Author

krutoo commented Oct 23, 2023

@rick-liruixin Don't you have time yet?

@rick-liruixin
Copy link
Owner

@rick-liruixin Don't you have time yet?

Sorry, I've been too busy to update. It is now complete. @krutoo @ialse

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

No branches or pull requests

3 participants