fix:解决移动端 Dialog 滚动问题

This commit is contained in:
hzm
2026-03-12 21:53:11 +08:00
parent 7953b906a5
commit 8849b547ce
3 changed files with 49 additions and 27 deletions

View File

@@ -0,0 +1,18 @@
import { useEffect } from "react";
export function useBodyScrollLock(open) {
useEffect(() => {
if (!open) return;
const scrollY = window.scrollY;
document.body.style.position = "fixed";
document.body.style.top = `-${scrollY}px`;
return () => {
document.body.style.position = "";
document.body.style.top = "";
window.scrollTo(0, scrollY);
};
}, [open]);
}