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> ); }; |
效果:
分类:
Web前端 / react
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
2022-04-12 setParameter和setParameterList的区别