大家好!我叫戴向天
QQ群:602504799
QQ:809002582
<template>
<div v-drag :class="{'fixed':isFixed}">
<slot/>
</div>
</template>
<script>
export default {
props:{
isFixed:{
type:Boolean,
default:true
}
},
directives:{
drag(el) {
el.onmousedown = (e)=>{
e.stopPropagation()
let
disx = e.pageX - el.offsetLeft,
disy = e.pageY - el.offsetTop
document.body.onselectstart = ()=> false
document.onmousemove = (e)=>{
el.style.left = e.pageX - disx + 'px'
el.style.top = e.pageY - disy + 'px'
}
document.onmouseup = ()=> document.body.onselectstart = document.onmousemove = document.onmouseup = null
}
el.onmouseleave = ()=> document.body.onselectstart = document.onmousemove = document.onmouseup = null
el.onmousemove = ()=> document.body.onselectstart = document.onmousemove = document.onmouseup = null
el.onmouseup = ()=> document.body.onselectstart = document.onmousemove = document.onmouseup = null
}
}
}
</script>
<style scoped>
.fixed{
position:fixed
}
</style>