当前位置: 首页 > news >正文

【Element-UI】实现el-drawer抽屉的左右拖拽宽度

对Element-UI的el-drawer抽屉控件实现拖拽功能。
1、新增drawer-drag.js

import Vue from 'vue'

Vue.directive('drawerDrag', {
  bind(el, binding, vnode, oldVnode) {
    const minWidth = 400
    const dragDom = el.querySelector('.el-drawer')
    dragDom.style.overflow = 'auto'

    const resizeElL = document.createElement('div')
    const img = new Image(24, 38)
    //拖拽图标,不需要可去除
    //img.src = require('@/assets/images/portal_2.png')
    //dragDom.appendChild(img)
    dragDom.appendChild(resizeElL)
    resizeElL.style.cursor = 'w-resize'
    resizeElL.style.position = 'absolute'
    resizeElL.style.height = '100%'
    resizeElL.style.width = '10px'
    resizeElL.style.left = '0px'
    resizeElL.style.top = '0px'
    //img.style.position = 'absolute'
    //img.style.left = '-12px'
    //img.style.top = '50%'

    resizeElL.onmousedown = (e) => {
      const elW = dragDom.clientWidth
      const EloffsetLeft = dragDom.offsetLeft
      const clientX = e.clientX
      document.onmousemove = function(e) {
        e.preventDefault()
        // 左侧鼠标拖拽位置
        if (clientX > EloffsetLeft && clientX < EloffsetLeft + 10) {
          // 往左拖拽
          if (clientX > e.clientX) {
            dragDom.style.width = elW + (clientX - e.clientX) + 'px'
          }
          // 往右拖拽
          if (clientX < e.clientX) {
            if (dragDom.clientWidth >= minWidth) {
              dragDom.style.width = elW - (e.clientX - clientX) + 'px'
            }
          }
        }
      }
      // 拉伸结束
      document.onmouseup = function(e) {
        document.onmousemove = null
        document.onmouseup = null
      }
    }
  }
})

2、引入drawer-drag.js并且使用
引入js:

import '@/utils/drawer-drag'

在el-drawer加入v-drawerDrag使用

 <el-drawer
          v-drawerDrag
</el-drawer>

实现来源:
1、https://www.cnblogs.com/younghxp/p/17539907.html
2、https://www.jianshu.com/p/5b250e7f94f3

相关文章:

  • 使用Scikit-image进行图像处理入门
  • 微服务SpringSession解析部署使用全流程
  • Redis篇(应用案例 - UV统计)(持续更新迭代)
  • 【常读常悟】《大数据之路-阿里巴巴大数据实践》一书读书摘要
  • Java题集(从入门到精通)04
  • Hive数仓操作(八)
  • python爬虫 - 初识爬虫
  • Updates were rejected because the tip of your current branch is behind 的解决方法
  • 推荐 uniapp 相对好用的海报生成插件
  • 【课程学习】Wireless Communications
  • java入门基础(一篇搞懂)
  • fiddler抓包17_简单接口测试(Composer请求编辑)
  • 疾风大模型气象,基于大模型预测未来天气的探索
  • Tomcat监控与调优:比Tomcat Manager更加强大的Psi-Probe
  • 使用Java调用GeoTools实现全球国家矢量数据入库实战
  • 信息学奥赛:青少年编程的高光舞台,通向未来科技的敲门砖
  • 搭建企业级私有仓库harbor
  • 新手小白在做副业时要注意哪些细节?
  • OpenCV threhold()函数
  • 【JNI】普通类型的基本使用
  • 某博主遭勒索后自杀系自导自演,成都警方立案调查
  • 93岁南开退休教授陈生玺逝世,代表作《明清易代史独见》多次再版
  • 巴基斯坦全国航班仍持续延误或取消
  • “海豚音”依旧,玛丽亚·凯莉本周来沪开唱
  • 湖北石首市委副书记、市长付勇接受审查调查
  • 宣布停火后,印控克什米尔地区再次传出爆炸声