当前位置:网站首页>antUI中a-modal 拖拽功能制作
antUI中a-modal 拖拽功能制作
2022-07-26 09:21:00 【周小盗】
写博客是为了做笔记!!!
antUI中a-modal 拖拽功能制作
一、在utils中创建drag.js文件,内容如下:
import Vue from 'vue'
// v-dialogDrag: 弹窗拖拽
Vue.directive('dragModal', {
bind(el, binding, vnode, oldVnode) {
const dialogHeaderEl = el.querySelector('.ant-modal-header')
const dragDom = el.querySelector('.ant-modal')
dialogHeaderEl.style.cursor = 'move'
// 获取原有属性 ie dom元素.currentStyle 火狐谷歌 window.getComputedStyle(dom元素, null);
const sty = dragDom.currentStyle || window.getComputedStyle(dragDom, null)
dialogHeaderEl.onmousedown = (e) => {
// 鼠标按下,计算当前元素距离可视区的距离
const disX = e.clientX - dialogHeaderEl.offsetLeft
const disY = e.clientY - dialogHeaderEl.offsetTop
// 获取到的值带px 正则匹配替换
let styL, styT
// 注意在ie中 第一次获取到的值为组件自带50% 移动之后赋值为px
if (sty.left.includes('%')) {
styL = +document.body.clientWidth * (+sty.left.replace(/\%/g, '') / 100)
styT = +document.body.clientHeight * (+sty.top.replace(/\%/g, '') / 100)
} else {
styL = +sty.left.replace(/\px/g, '')
styT = +sty.top.replace(/\px/g, '')
}
document.onmousemove = function (e) {
// 通过事件委托,计算移动的距离
const l = e.clientX - disX
const t = e.clientY - disY
// 移动当前元素
dragDom.style.left = `${
l + styL}px`
dragDom.style.top = `${
t + styT}px`
// 将此时的位置传出去
// binding.value({
x:e.pageX,y:e.pageY})
}
document.onmouseup = function (e) {
document.onmousemove = null
document.onmouseup = null
}
}
}
})
二、在main.js中引入:
import '@/utils/drag'
三、使用:
注意命令和上方drag.js中声明的一致。
然后这个弹窗就可以进行拖拽了。
总结
如果要制作其他UI框架中的弹窗拖拽功能,只需要把drag.js中的元素替换掉即可。
边栏推荐
猜你喜欢

服务器内存故障预测居然可以这样做!

Announcement | FISCO bcos v3.0-rc4 is released, and the new Max version can support massive transactions on the chain
![[MySQL] how to execute an SQL statement (2)](/img/7b/53f8756458cc318e2f417b1cc0c3f8.png)
[MySQL] how to execute an SQL statement (2)
![[MySQL] detailed explanation of redo log, undo log and binlog (4)](/img/67/6e646040c1b941c270b3efff74e94d.png)
[MySQL] detailed explanation of redo log, undo log and binlog (4)

Stm32+mfrc522 completes IC card number reading, password modification, data reading and writing

Windows通过命令备份数据库到本地

性格测试系统v1.0

Mysql事务

arcgis的基本使用4

Object 的Wait Notify NotifyAll 源码解析
随机推荐
Selection and practice of distributed tracking system
【Mysql】redo log,undo log 和binlog详解(四)
什么是异步操作
2022 Shanghai safety officer C certificate examination questions and mock examination
会议OA项目(三)---我的会议(会议排座、送审)
JS output diamond on the console
"Could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32"
Your login IP is not within the login mask configured by the administrator
Conditions for JVM to trigger minor GC
【ARKit、RealityKit】把图片转为3D模型
arcgis的基本使用4
MySQL transaction
Vertical search
Server memory failure prediction can actually do this!
760. String length
李沐d2l(四)---Softmax回归
对象型的集合按某个属性的值进行去重
大二上第五周学习笔记
JS closure: binding of functions to their lexical environment
756. Serpentine matrix