可拖动大小页面

上效果

在这里插入图片描述
在这里插入图片描述

上代码

<template>
  <div class="box">
    <div class="left">盒子1</div>
    <div class="resize"></div>
    <div class="mid">盒子2</div>
    <div class="resize2"></div>
    <div class="right">盒子3</div>
  </div>
</template>

<script>
export default {
  data () {
    return {}
  },
  mounted () {
    this.dragControllerDiv()
  },
  methods: {
    dragControllerDiv: function () {
      var resize = document.getElementsByClassName('resize')[0]
      var resize2 = document.getElementsByClassName('resize2')[0]
      var left = document.getElementsByClassName('left')[0]
      var right = document.getElementsByClassName('right')[0]
      var mid = document.getElementsByClassName('mid')[0]
      var box = document.getElementsByClassName('box')[0]
      resize.onmousedown = function (e) {
        var startX = e.clientX
        resize.left = resize.offsetLeft
        document.onmousemove = function (e) {
          var endX = e.clientX
          var rightW = right.offsetWidth
          var moveLen = resize.left + (endX - startX)
          var maxT = box.clientWidth - resize.offsetWidth
          if (moveLen < 150) moveLen = 150
          if (moveLen > maxT - rightW - 155) moveLen = maxT - rightW - 155
          resize.style.left = moveLen
          left.style.width = moveLen + 'px'
          mid.style.width = (box.clientWidth - moveLen - rightW - 10) + 'px'
        }

        document.onmouseup = function (evt) {
          document.onmousemove = null
          document.onmouseup = null
          resize.releaseCapture && resize.releaseCapture()
        }
        resize.setCapture && resize.setCapture()
        return false
      }
      resize2.onmousedown = function (e) {
        var startX = e.clientX
        resize2.left = resize2.offsetLeft
        document.onmousemove = function (e) {
          var endX = e.clientX
          var leftW = left.offsetWidth
          var moveLen = resize2.left + (endX - startX) - leftW
          var maxT = box.clientWidth - resize2.offsetWidth - 5
          if (moveLen < 150) moveLen = 150
          if (moveLen > maxT - leftW - 150) moveLen = maxT - leftW - 150
          resize2.style.left = moveLen
          mid.style.width = moveLen - 5 + 'px'
          right.style.width = (box.clientWidth - moveLen - leftW - 10) + 'px'
        }
        document.onmouseup = function (evt) {
          document.onmousemove = null
          document.onmouseup = null
          resize2.releaseCapture && resize2.releaseCapture()
        }
        resize2.setCapture && resize2.setCapture()
        return false
      }
    }
  }
}
</script>

<style lang="less" scoped>
.box {
  width: 100%;
  height: 100%;
  overflow: hidden;
  .left {
    float: left;
    width: 33%;
    height: 100%;
    background: skyblue;
  }
  .mid {
    float: left;
    width: calc(~"34% - 10px");
    height: 100%;
    background: gray;
  }
  .right {
    float: left;
    width: 33%;
    height: 100%;
    background: skyblue;
  }
  .resize,
  .resize2 {
    width: 5px;
    height: 100%;
    cursor: w-resize;
    float: left;
  }
}
</style>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值