Kaynağa Gözat

fix: resolve issue where floating buttons for navigation area display outside the community

ddx 1 ay önce
ebeveyn
işleme
9232b30fa5
1 değiştirilmiş dosya ile 14 ekleme ve 4 silme
  1. 14 4
      src/layouts/NavbarFloat.tsx

+ 14 - 4
src/layouts/NavbarFloat.tsx

@@ -32,10 +32,20 @@ const NavbarFloat: React.FC<NavbarFloatProps> = ({
 
   React.useEffect(() => {
     // 组件挂载后再安全访问 window
-    setBtnPos({
-      x: window.innerWidth - 100,
-      y: window.innerHeight - 100,
-    });
+    const updatePosition = () => {
+      setBtnPos({
+        x: window.innerWidth - 100,
+        y: window.innerHeight - 100,
+      });
+    };
+
+    updatePosition(); // 初始化位置
+
+    window.addEventListener('resize', updatePosition);
+
+    return () => {
+      window.removeEventListener('resize', updatePosition);
+    };
   }, []);
   const [dragged, setDragged] = useState(false);
   const dragging = useRef(false);