6 changed files with 76 additions and 11 deletions
@ -0,0 +1,49 @@ |
|||
<!-- |
|||
*@描述: 拖拽组件 |
|||
控制 消息弹窗组件 Notification |
|||
*@作者: |
|||
*@日期: |
|||
*@版本:1.0 |
|||
*/ |
|||
--> |
|||
<template> |
|||
<div class="draggable" @mousedown="draggable"></div> |
|||
</template> |
|||
<script setup lang="ts"> |
|||
const draggable = function (e: any) { |
|||
let odiv = e.target; //获取目标元素 |
|||
let pdiv = odiv.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement; |
|||
//算出鼠标相对元素的位置 |
|||
let disX = e.clientX - pdiv.offsetLeft; |
|||
let disY = e.clientY - pdiv.offsetTop; |
|||
document.onmousemove = (e) => { |
|||
//鼠标按下并移动的事件 |
|||
//用鼠标的位置减去鼠标相对元素的位置,得到元素的位置 |
|||
let left = e.clientX - disX; |
|||
let top = e.clientY - disY; |
|||
pdiv.style.left = left + 'px'; |
|||
pdiv.style.top = top + 'px'; |
|||
odiv.style.cursor = 'move'; |
|||
}; |
|||
document.onmouseup = (e) => { |
|||
document.onmousemove = null; |
|||
document.onmouseup = null; |
|||
}; |
|||
|
|||
} |
|||
</script> |
|||
<style lang="less" scoped> |
|||
.draggable { |
|||
width: 110%; |
|||
height: 52px; |
|||
position: absolute; |
|||
top: -52px; |
|||
left: -26px; |
|||
background-color: rgba(0, 0, 0, 0); |
|||
z-index: 2; |
|||
} |
|||
|
|||
.draggable:hover { |
|||
cursor: move; |
|||
} |
|||
</style> |
@ -0,0 +1,17 @@ |
|||
<template> |
|||
<div class="label-edit-model"> |
|||
<Draggable></Draggable> |
|||
<Button>123</Button> |
|||
</div> |
|||
</template> |
|||
|
|||
<script setup lang='ts'> |
|||
import {Button} from 'ant-design-vue' |
|||
import Draggable from '@/components/Draggable.vue' |
|||
</script> |
|||
|
|||
<style scoped lang='less'> |
|||
.label-edit-model{ |
|||
position: relative; |
|||
} |
|||
</style> |
Loading…
Reference in new issue