mouseMove模拟拖拽,封装指令
2024-09-08 15:57:26
最近项目里常常使用拖拽改变元素位置或者大小的需求,cv法文件找的脑阔疼,索性试试写一个指令。
说起指令,提一嘴,vue3没有了根元素唯一的限制后,仿佛指令绑定在组件上就不能生效了。
import type { Directive } from 'vue'
const mouseDownMove: Directive = {
mounted(el, binding) {
const { mouseDown, mouseMove, mouseUp } = binding.value
el.onmousedown = (event) => {
mouseDown && mouseDown(event)
document.onselectstart = function () {
return false
}
document.ondragstart = function () {
return false
}
document.onmousemove = (event) => {
mouseMove && mouseMove(event)
}
window.onmouseup = (event) => {
document.onmousemove = null
document.onselectstart = null
window.onmouseup = null
document.ondragstart = null
mouseUp && mouseUp(event)
<span class="xy-scrollbar__thumb"
:style="thumbX"
v-mouseDownMove="handleMouseDownX"></span>
const mouseDownMove = {
mouseDown(){},
mouseMove(){},
mouseUp(){},
}
最新文章
- Java MySql 批量插入数据库addBatch
- 深入Java核心 Java中多态的实现机制(1)
- dotnet文件操作
- .net 架构师/经理招聘,长期有效
- svn代码回滚命令
- POJ 2992	 Divisors
- 转:ASCII码表_全_完整版
- andengine游戏引擎总结基础篇
- grunt安装使用简介
- 一次php涉及跨域功能的麻烦及解决方案
- Java中的回调
- [SDOI2015]序列统计
- mybatis数据源源码剖析(JNDI、POOLED、UNPOOLED)
- 免费了 -- EXCEL插件 智表ZCELL 普及版V1.0 发布了!!!
- centos 7 之nginx
- 1.Ansible安装以及配置
- (转)Spring文件上传,包括一次选中多个文件
- Gym - 101002D:Programming Team (01分数规划+树上依赖背包)
- Oracle 存储过程了解
- how to create a custom form for sharepoint list
热门文章
- 第五章:Admin管理后台 - 2:自定义Admin actions
- Elasticsearch from/size-浅分页查询-深分页 scroll-深分页search_after深度查询区别使用及应用场景
- C++面向对象编程之C++11语法糖
- 关于maven插件在Myeclipse中的使用
- 使用开源计算引擎提升Excel格式文件处理效率
- 测试杂谈——一条SQL引发的思考(二)
- instanceof的使用和向下转型
- [Thread] 多线程顺序执行
- 虚拟机安装Linux系统的网络配置
- resutful的使用和增强版的swagger2