当前位置:网站首页>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中的元素替换掉即可。
边栏推荐
猜你喜欢

NTT(快速数论变换)多项式求逆 一千五百字解析
![[MySQL] how to execute an SQL statement (2)](/img/7b/53f8756458cc318e2f417b1cc0c3f8.png)
[MySQL] how to execute an SQL statement (2)

Nuxt - Project packaging deployment and online to server process (SSR server rendering)

Polynomial open root

Advanced mathematics | Takeshi's "classic series" daily question train of thought and summary of error prone points

Exception handling mechanism II

Vertical search

【线上问题】Timeout waiting for connection from pool 问题排查

2022茶艺师(中级)特种作业证考试题库模拟考试平台操作

多项式开根
随机推荐
Your login IP is not within the login mask configured by the administrator
CF1481C Fence Painting
2B and 2C
[MySQL] how to execute an SQL statement (2)
大二上第二周学习笔记
Summary of common activation functions for deep learning
[MySQL] detailed explanation of MySQL lock (III)
Ext4 file system opens dir_ After nlink feature, link_ Use link after count exceeds 65000_ Count=1 means the quantity is unknown
【Mysql】一条SQL语句是怎么执行的(二)
760. 字符串长度
李沐d2l(四)---Softmax回归
您的登录IP不在管理员配置的登录掩码范围内
"No input file specified" problem handling
Li Mu D2L (VI) -- model selection
[arkit, realitykit] turn pictures into 3D models
【线上死锁分析】由index_merge引发的死锁事件
QT | about how to use EventFilter
省政府召开全省高温天气安全防范工作电视电话会议
When you click input, the border is not displayed!
Mysql事务