export default {
install(Vue) {
// v-dialogDrag: 弹窗拖拽
Vue.directive('dragModal', (el, bindings, vnode) => {
Vue.nextTick(() => {
const { visible, destroyOnClose } = vnode.componentInstance
// 防止未定义 destroyOnClose 关闭弹窗时dom未被销毁,指令被重复调用
if (!visible) return
const modal = el.getElementsByClassName('ant-modal')[0]
const header = el.getElementsByClassName('ant-modal-header')[0]
let left = 0
let top = 0
header.style.cursor = 'move'
// 未定义 destroyOnClose 时,dom未被销毁,关闭弹窗再次打开,弹窗会停留在上一次拖动的位置
if (!destroyOnClose) {
left = modal.left || 0
top = modal.top || 0
}
// top 初始值为 offsetTop
top = top || modal.offsetTop
header.onmousedown = e => {
const startX = e.clientX
const startY = e.clientY
header.left = header.offsetLeft
header.top = header.offsetTop
el.onmousemove = event => {
const endX = event.clientX
const endY = event.clientY
modal.left = header.left + (endX - startX) + left
modal.top = header.top + (endY - startY) + top
modal.style.left = modal.left + 'px'
modal.style.top = modal.top + 'px'
}
el.onmouseup = event => {
left = modal.left
top = modal.top
el.onmousemove = null
el.onmouseup = null
header.releaseCapture && header.releaseCapture()
}
header.setCapture && header.setCapture()
}
})
})
}
}
import '@/utils/drag'
<a-modal
v-dragModal
:title="editModal.modalTitle + '详情'"
:visible="editModal.visible"
destroy-on-close
:footer="null"
:width="1200"
@cancel="editModal.visible = false"
>
<div style="height: 500px">
1
</div>
</a-modal>
原文地址:https://blog.csdn.net/i_am_a_div/article/details/134685999
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_10943.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。