主要思路
- 在需要拖拽宽度的区域设置一个div,高度设为 100%,宽度尽量窄一些(也不要太窄,3~6px左右)
- 在此div上绑定当“鼠标按下”时,触发document绑定“鼠标移动”方法和"鼠标抬起"方法
- 通过鼠标移动方法不断获取当前鼠标位置,设置需要变化大小div的宽高。
- 鼠标抬起时取消鼠标移动方法和鼠标抬起方法的绑定。
<template> <div class="container" id="content_box"> <div class="tab">左侧Tab</div> <div class="menu" ref="menu"> 左侧菜单 <div class="menu-resize" ref="menuResize"></div> </div> <div class="content"> 中心区域 <div class="opera" ref="opera"> <div class="opera-resize" ref="operaResize"></div> 操作区域 </div> </div> </div> </template> <script> export default { name: "dropWidth", mounted() { this.$nextTick(() => { this.dropSize(); }) }, methods: { dropSize() { let that = this, menuWidth = 200, operaHeight = 200; this.$refs.menuResize.onmousedown = function () { document.onmousemove = function (e) { let clientX = e.clientX; // 最大宽度 if(clientX>=330){ clientX = 330; } // 最小宽度 if(clientX<=230){ clientX = 230; } // TODO 这里减的是最左侧tab的宽度 menuWidth = clientX - 30; that.$refs.menu.style.width = clientX - 30 +"px"; } document.onmouseup = function () { console.log('当前宽度', menuWidth); document.onmousemove = null; document.onmouseup = null; that.releaseCapture && that.releaseCapture() } } this.$refs.operaResize.onmousedown = function () { document.onmousemove = function (e) { let clientY = e.clientY; console.log(clientY) // 最大宽度 if(clientY<=100){ clientY = 100; } // 最小宽度 if(clientY>=300){ clientY = 300; } operaHeight = clientY; // TODO 这里需要取反向 that.$refs.opera.style.height = 400 - clientY +"px"; } document.onmouseup = function () { console.log('当前宽度', operaHeight); document.onmousemove = null; document.onmouseup = null; that.releaseCapture && that.releaseCapture() } } } } } </script> <style scoped> .container { width: 1000px; height: 400px; border: 2px solid #dddddd; display: flex; justify-content: center; } .tab { width: 30px; height: 100%; background-color: #EC8C32; flex-shrink: 0; flex-grow: 0; } .menu { width: 200px; background-color: #AAB6E0; flex-shrink: 0; flex-grow: 0; position: relative; } .content { width: 100%; position: relative; } .opera { width: 100%; height: 200px; position: absolute; bottom: 0; background-color: #F2BE25; } .menu-resize { width: 5px; height: 100%; position: absolute; top: 0; right: 0; cursor: col-resize; } .opera-resize { width: 100%; height: 5px; position: absolute; top: 0; left: 0; cursor: row-resize; } </style>
实现效果
热门文章
- 宠物店需要办什么证件(开一家宠物店大概需要投资多少钱)
- 兽用疫苗放在冰箱对食物有伤害吗(兽用疫苗可以放家用冰箱里吗)
- 动物防疫疫苗费取消的相关文件是 动物防疫疫苗费取消的相关文件是什么
- 2月15日|V2ray/SSR/Clash/Shadowrocket每天更新18.3M/S免费节点订阅链接地址分享
- mysql创建表分区详细介绍及示例
- 领养宠物的软件有哪些 领养宠物的软件有哪些免费
- 济南宠物领养中心在哪个位置呀(济南宠物寄养中心)
- 1月30日|SSR/Clash/V2ray/Shadowrocket每天更新21.1M/S免费节点订阅链接地址分享
- 领养狗狗需要什么手续(领养狗狗需要什么流程)
- 动物疫苗价格表图片大全及价格图 动物疫苗价格表图片大全及价格图