|
@@ -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);
|