首页 > 其他分享 >elementui el-draw自定义拖拽指令

elementui el-draw自定义拖拽指令

时间:2023-07-10 09:26:08浏览次数:39  
标签:body el draw const 自定义 realHeight document 拖拽

一、问题引入

场景:el-draw抽屉高度(宽度)可拖拽

二、解决方案

使用vue指令,el-draw打开后,插入一个元素,绑定鼠标事件实现拖拽

主要代码如下

/**
    * el-drawer 拖拽高度指令
    */
    Vue.directive('el-drawer-drag-height', {
      bind(el, binding, vnode, oldVnode) {
        const drawerEle = el.querySelector('.el-drawer')
        // 创建触发拖拽的元素
        const dragItem = document.createElement('div')
        // 将元素放置到抽屉的左边边缘
        dragItem.style.cssText = 'height: 5px;width: 100%;cursor: s-resize;position: absolute;top: 0;'
        drawerEle.append(dragItem)

        const moveCallback = function(e){
          // e.preventDefault();
          // e.stopPropagation();
          // 获取鼠标距离浏览器上边缘的距离
          let realHeight = document.body.clientHeight - e.pageY
          const height30 = document.body.clientHeight * 0.4
          const height80 = document.body.clientHeight * 1
          // 高度不能小于 40%
          realHeight = realHeight > height80 ? height80 : realHeight < height30 ? height30 : realHeight
          drawerEle.style.height = realHeight + 'px'
        }

        dragItem.addEventListener('mousedown', () => {
          // 拖拽时禁用文本选中
          document.body.style.userSelect = 'none'
          document.addEventListener('mousemove', moveCallback)
          document.addEventListener('mouseup',()=>{
            // 拖拽时结束时,取消禁用文本选中
            document.body.style.userSelect = 'initial'
            document.removeEventListener('mousemove', moveCallback)
            // document.removeEventListener('mouseup')
          })
        })
      }
    })

 

标签:body,el,draw,const,自定义,realHeight,document,拖拽
From: https://www.cnblogs.com/younghxp/p/17539907.html

相关文章

  • Excel让行等高
     把鼠标放到这个位置,变成这个形状;然后在按住鼠标左键,往下拉,选中你要操作的所有行;最后调整一行的高度,其他行的高度就相同了。 ......
  • elementUI 下拉框select可编辑option
    下拉框里点击编辑图标出现输入框,但是点击输入框时,下拉框会自动关闭,如何不让下拉框自动关闭?     <el-selectv-model="selectValue"ref="refSelect"placeholder="请选择"class="select"@visible-change="visibleChange"......
  • cyber hello world
    CPP文件#include<cyber/cyber.h>intmain(intargc,char*argv[]){apollo::cyber::Init(argv[0]);//初始化日志AINFO<<"helloworld"<<endl;//输出日志return0;}BUILD文件及编译执行//demo_cc目录下新建buld文件,demo_cc目录即为cpp所在目......
  • Qt源码阅读(五)-deleteLater
    QtdeleteLater作用及源码分析个人经验总结,如有错误或遗漏,欢迎各位大佬指正......
  • shell参数使用
    shell参数使用说明参数说明$0执行脚本本身的名字。$1传递给脚本的第一个参数。$#脚本的参数个数。$*脚本的所有参数。当被双引号("$*")包含时,会将所有参数当作一个整体来输出。$@与$*类似,但是可以当作数组用。当被双引号("$@")包含时,会将各个参数分开。$?......
  • Linux,shell入门,第二篇
    #!/bin/bash#显示出本机的ip地址方法一#ipa|grepdynamic|tr-s''\/|cut-d'/'-f3#显示出本机的ip地址方法二ipa|sed-rn's/(.*inet)([0-9].*)(\/[0-9].*)(brd.*)/\2/p'#显示出本机ip地址方法三#hostname-I#把ip地址赋值给变量ipaddr,上述三种方法均可ipaddr=......
  • 时间序列转图像:相对位置矩阵(Relative Position Matrix)-Python版复现
    时间序列分类(TSC)在时间序列数据挖掘任务中备受关注,已经应用到各个领域。随着卷积神经网络(ConvolutionalNeuralNetwork,CNN)的迅速发展,基于卷积神经网络的TSC方法直到最近才开始出现。因此,提出了一个新的深度学习框架,使用相对位置矩阵(RelativePositionMatrix,RPM)和卷积神经......
  • python: FileHelper
     #encoding:utf-8#版权所有2023涂聚文有限公司#许可信息查看:#描述:#Author:geovindu,GeovinDu涂聚文.#IDE:PyCharm2023.1python311#Datetime:2023/7/919:12#User:geovindu#Product:PyCharm#Project:pythonTkinterDe......
  • linux shell template
    Replaceenvironmentvariablesinafilewiththeiractualvalues?#config.xml<property><name>instanceId</name><value>$INSTANCE_ID</value></property><property><name>rootPath</name>......
  • USB C Power Delivery also support data transfer?
    https://www.ti.com/lit/ds/symlink/tps65987ddk.pdf?ts=1688854016963&ref_url=https%253A%252F%252Fwww.ti.com%252Fproduct%252FTPS65987DDK  ThepowerinputportonUSB-Cdockscanonlybeusedforpowerinput.ThereasonwhyUSB-Cpowerinputportscan......