preline
preline copied to clipboard
Fix get body current scrollbar size overlay
Emulate scrollbar feature in overlay plugin
The current method getScrollbarSize in overlay plugin does not work properly. It produce layout shift:
- On phone, overlay plugin adds padding right to the body
- On PC when the body does not have overflow content, the plugin still add padding right the body
Desire result
- Do not add body padding right on phone
- Do not add body padding right when body does not have overlay content
Fix
Calculate the scollbar size before setting body overflow hidden when open overlay
- bodyWidth = getComputedStyle(document.body).width;
- scrollbarSize = window.innerWidth - bodyWidth