Fix modal offset: use overflow:hidden instead of position:fixed on body
This commit is contained in:
BIN
chrome_11eKLevsrE.png
Normal file
BIN
chrome_11eKLevsrE.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 368 KiB |
@@ -35,19 +35,15 @@ export default function CatModal({ catId, onClose }: CatModalProps) {
|
||||
useEffect(() => { if (data?.cat) setLikeCount(data.cat.likes_count); }, [data]);
|
||||
useEffect(() => {
|
||||
const scrollY = window.scrollY;
|
||||
document.documentElement.style.overflow = 'hidden';
|
||||
document.documentElement.style.height = '100%';
|
||||
document.body.style.overflow = 'hidden';
|
||||
document.body.style.position = 'fixed';
|
||||
document.body.style.top = `-${scrollY}px`;
|
||||
document.body.style.left = '0';
|
||||
document.body.style.right = '0';
|
||||
document.body.style.width = '100%';
|
||||
document.body.style.height = '100%';
|
||||
return () => {
|
||||
document.documentElement.style.overflow = '';
|
||||
document.documentElement.style.height = '';
|
||||
document.body.style.overflow = '';
|
||||
document.body.style.position = '';
|
||||
document.body.style.top = '';
|
||||
document.body.style.left = '';
|
||||
document.body.style.right = '';
|
||||
document.body.style.width = '';
|
||||
document.body.style.height = '';
|
||||
window.scrollTo(0, scrollY);
|
||||
};
|
||||
}, []);
|
||||
|
||||
Reference in New Issue
Block a user