<div style="display: flex;">
<a-layout class="box_gsbz" ref="box_gsbz">
<a-layout-sider :style="{ maxWidth: '0px', minWidth: '0px' }"></a-layout-sider>
<div class="leftMove left_gsbz" :style="{ height: siderheigth }">
</div>
<div class="resize_gsbz" title="收缩"></div>
<a-layout-content class="mid_gsbz" :style="{height: siderheigth, backgroundColor:'white'}">
</a-layout-content>
</a-layout>
method
mounted() {
this.loadData()
*/
this.gsbz_mouse()
},
gsbz_mouse() {
const resize = document.getElementsByClassName('resize_gsbz')
const left = document.getElementsByClassName('left_gsbz')
const mid = document.getElementsByClassName('mid_gsbz')
const box = document.getElementsByClassName('box_gsbz')
for (let i = 0; i < resize.length; i++) {
//鼠标悬浮事件
resize[i].onmousemove = function (e) {
//颜色改变提醒
resize[i].style.background = '#40a9ff'
}
//鼠标移出事件
resize[i].onmouseout = function (e) {
//颜色恢复
resize[i].style.background = '#E9EBF1'
}
// 鼠标按下事件
resize[i].onmousedown = function (e) {
//颜色改变提醒
resize[i].style.background = '#40a9ff'
const startX = e.clientX
resize[i].left = resize[i].offsetLeft
// 鼠标拖动事件
document.onmousemove = function (e) {
resize[i].style.background = '#40a9ff'
var endX = e.clientX
var moveLen = resize[i].left + (endX - startX) // (endx-startx)=移动的距离。resize[i].left+移动的距离=左边区域最后的宽度
var maxT = box[i].clientWidth - resize[i].offsetWidth // 容器宽度 - 左边区域的宽度 = 右边区域的宽度
if (moveLen < 200) moveLen = 200 // 左边区域的最小宽度为300px
if (moveLen > maxT - 300) moveLen = maxT - 300 //右边区域最小宽度为300px
resize[i].style.left = moveLen // 设置左侧区域的宽度
console.log(moveLen)
for (let j = 0; j < left.length; j++) {
left[j].style.minWidth = moveLen + 'px'
left[j].style.flex = `0 0 ${moveLen}px`
left[j].style.maxWidth = moveLen + 'px'
mid[j].style.width = box[i].clientWidth - moveLen - 12 - 4 + 'px'
}
}
// 鼠标松开事件
document.onmouseup = function (evt) {
//颜色恢复
resize[i].style.background = '#E9EBF1'
document.onmousemove = null
document.onmouseup = null
resize[i].releaseCapture && resize[i].releaseCapture() //当你不在需要继续获得鼠标消息就要应该调用ReleaseCapture()释放掉
}
resize[i].setCapture && resize[i].setCapture() //该函数在属于当前线程的指定窗口里设置鼠标捕获
return false
}
}
},
css
.resize_gsbz {
cursor: col-resize;
float: left;
position: relative;
transition-delay: 0.05s;
/*top: 45%;*/
width: 5px;
/*height: 104px;*/
margin-left: 0px;
/*background-color: #cdcccc;*/
/*margin-top: 17%;*/
}
//解决拉伸不显示问题
.box_gsbz {
display: -webkit-box !important;
}