react 的react-resizable组件,实现可拖动的变动大小的效果

上网找遍的办法,也没找到能否实现需求的。最后自己填填补补,实现了需求

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const ResizableBox = () => {
  const [allWidth, setAllWidth] = React.useState(800);
  const [width, setWidth] = React.useState(500);
  const [width2, setWidth2] = React.useState(200);
 
  const onResize = (event, { size }) => {
    console.log("size.width = ",size.width);
    console.log("size.height = ",size.height);
    const widthIndex = allWidth - size.width
    setWidth(size.width);
    setWidth2(widthIndex)
  };
 
  return (
    <>
      <div  style={{display: 'flex',width: `${allWidth}px`}}>
        <Resizable
          width={width}
          onResize={onResize}
          draggableOpts={{ grid: [25, 25] }} // 可选项,用于设置拖动的网格大小
        >
          <div style={{ width: `${width}px`, border: '1px solid #ccc' }}>
            Resizable Box
          </div>
        </Resizable>
        <Resizable
          width={width2}
          onResize={onResize}
          draggableOpts={{ grid: [25, 25] }} // 可选项,用于设置拖动的网格大小
        >
          <div style={{ width: `${width2}px`, border: '1px solid #bbb' }}>
            Resizable Box
          </div>
        </Resizable>
      </div>
       
    </>
  );
};
 
const MyComponent = () => {
  return (
    <div className="app">
      <ResizableBox />
    </div>
  );
};

 效果:

 

posted @   信铁寒胜  阅读(737)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
历史上的今天:
2022-04-12 setParameter和setParameterList的区别
点击右上角即可分享
微信分享提示