I figured out a solution to my problem that did not involve knowing the width of the scroll bar.
First of all the question was poorly formulated for 2 reasons:
- On mobile devices the scrollbar is not the same as on large screens
so it does not get in the way
- It did interfere with my lightbox plugin (fancybox) but the solution is much simpler
If anyone comes here because of a similar issue, the solution was to apply
overflow-y: scroll;
overflow-y: overlay;
to the <body>
tag instead of html
as the lightbox plugin could overwrite it that way once you click on an image.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…