zoukankan      html  css  js  c++  java
  • vue3可拖拽容器宽度

    <template>
      <div class="main" ref="main">
        <div class="left"></div>
        <div class="pull" >⋮</div>
        <div class="right"></div>
      </div>
    </template>
    <script>
    import {onMounted} from "vue";
    export default defineComponent({
      setup() {
        const dragControllerDiv = () => {
          var pull= document.getElementsByClassName("pull");
          var left = document.getElementsByClassName("left");
          var right = document.getElementsByClassName("right");
          var main = document.getElementsByClassName("main");
          for (let i = 0; i < pull.length; i++) {
            pull[i].onmousedown = function (e) {
              pull[i].style.background = "#818181";
              var startX = e.clientX;
              pull[i].left = pull[i].offsetLeft;
              document.onmousemove = function (e) {
                var endX = e.clientX;
                var moveLen = pull[i].left + (endX - startX); 
                var maxT = main[i].clientWidth - pull[i].offsetWidth; 
                if (moveLen < 32) moveLen = 32; 
                if (moveLen > maxT - 150) moveLen = maxT - 150; 
                pull[i].style.left = moveLen; 
                for (let j = 0; j < left.length; j++) {
                  left[j].style.width = moveLen + "px";
                  right[j].style.width = main[i].clientWidth - moveLen - 10 + "px";
                }
              };
              document.onmouseup = function (evt) {
                pull[i].style.background = "#d6d6d6";
                document.onmousemove = null;
                document.onmouseup = null;
                pull[i].releaseCapture && pull[i].releaseCapture(); 
              };
              pull[i].setCapture && pull[i].setCapture(); 
              return false;
            };
          }
        };
        onMounted(() => {
          dragControllerDiv();
        });
        return {
          dragControllerDiv
        };
      },
    });
    </script>
    <style lang="less" scoped>
    .main{
       100%;
      height: 100vh;
      overflow: hidden;
      box-shadow: -1px 9px 10px 3px rgba(0, 0, 0, 0.11);
    }
    .left {
       calc(20% - 10px); 
      height: 100%;
      background: #ffffff;
      float: left;
    }
    .pull{
      cursor: col-resize;
      float: left;
      position: relative;
      top: 45%;
      background-color: #d6d6d6;
      border-radius: 5px;
      margin-top: -10px;
       10px;
      height: 50px;
      background-size: cover;
      background-position: center;
      font-size: 32px;
      color: white;
    }
    .pull:hover {
      color: #444444;
    }
    .right{
      float: left;
       80%; 
      height: 100%;
      background: #fff;
      box-shadow: -1px 4px 5px 3px rgba(0, 0, 0, 0.11);
    }
    </style>
  • 相关阅读:
    POJ 1811 Prime Test 素性测试 分解素因子
    sysbench的安装与使用
    电脑中已有VS2005和VS2010安装.NET3.5失败的解决方案
    I.MX6 show battery states in commandLine
    RPi 2B Raspbian system install
    I.MX6 bq27441 driver porting
    I.MX6 隐藏电池图标
    I.MX6 Power off register hacking
    I.MX6 Goodix GT9xx touchscreen driver porting
    busybox filesystem httpd php-5.5.31 sqlite3 webserver
  • 原文地址:https://www.cnblogs.com/wxyz9527/p/14944132.html
Copyright © 2011-2022 走看看