随笔 - 23,  文章 - 3,  评论 - 16,  阅读 - 58992

 

 

 

需求:上下两个盒子之间添加可拖拽按钮,实现高度变化

  html:

复制代码
              <textarea
                :id="'mycode'+(index*1+1)"
                :ref="'mycode'+(index*1+1)"
                v-model="item.sqlContent"
                class="CodeMirror-hints"
                :class="'mycode'+(index*1+1)"
                placeholder="按Ctrl键进行代码提示"
              />
              <!-- 拖拽组件 -->
              <div class="resizeBtn"><span @mousedown="resizeDown" @mousemove="resizeMove" @mouseup="resizeUp">===</span></div>
              <el-tabs class="bottomTabsBox" style="height: 225px" size=mini v-model="activeSqlRes" type="card" @tab-click="handleSqlResClick"></el-tabs>          
复制代码

  css:

复制代码
    .CodeMirror {
      flex: 1;
     }
    .resizeBtn {
      background: #143152;
      text-align: center;
      height: 10px;
      line-height: 7px;
      color: gray;
      font-weight: 900;
      span {
        cursor: n-resize;
      }
    }
    .bottomTabsBox {
      height: 30%;
      background: $--sqlBg-color;
      border-top: 1px solid rgba(255,255,255,.2);
      z-index: 1;
    }
复制代码

 

出现问题的版本:

  1 卡顿

  2 不流畅

  3 鼠标快速移动无法改变高度

  4 mouseup无法释放

resizeBox: null,
resizeY: 0,
boxHeight: '225px', // 下部分盒子高度
复制代码
    resizeDown(e, index) {
      this.resizeBox = document.getElementsByClassName('bottomTabsBox')
      this.boxHeight = parseFloat(this.resizeBox[index].style.height)
      this.resizeY = e.clientY
    },
    resizeMove(e) {
        if (!this.resizeBox) return false
        let change = this.boxHeight + (this.resizeY - e.clientY)
        if (change < 40) return false
        this.resizeBox[index].style.height = change+ 'px'  
    },
    resizeUp(e) {
        this.resizeBox = null
    }
复制代码

 

优化后版本:超级丝滑~

html:

    <!-- 拖拽组件 -->
    <div class="resizeBtn"><span @mousedown="resizeDown($event, index)">===</span></div>
复制代码
    resizeDown(e, index) {
      this.resizeBox = document.getElementsByClassName('bottomTabsBox')
      this.boxHeight = parseFloat(this.resizeBox[index].style.height)
      this.resizeY = e.clientY
      
      document.onmousemove = (e) => {
        if (!this.resizeBox) return false
        let change = this.boxHeight + (this.resizeY - e.clientY)
        if (change < 40) return false  // 设置最小高度
        this.resizeBox[index].style.height = change+ 'px'
      }

      document.onmouseup = () => {
        this.resizeBox = null
        document.onmousemove = null;
      }
    }
复制代码

 

posted on   丶小馨  阅读(1974)  评论(2编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通

< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5
点击右上角即可分享
微信分享提示