Skip to content

Commit 62d7c44

Browse files
committed
fixed jittery effect when scroll bar vanishes by adding padding=scrollbar-width
1 parent bef40cb commit 62d7c44

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

frontend/src/components/Hamburger.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ const Hamburger = () => {
2626

2727
useEffect(() => {
2828
if (showMenu) {
29+
// Add padding when scrollbar vanishes
30+
const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
2931
document.body.style.overflow = 'hidden';
30-
} else {
31-
document.body.style.overflow = 'scroll';
32+
document.body.style.paddingRight = `${scrollbarWidth}px`;
3233
}
3334

3435
return () => {
3536
document.body.style.overflow = 'scroll';
37+
document.body.style.paddingRight = '0px';
3638
};
3739
}, [showMenu]);
3840

0 commit comments

Comments
 (0)