功能是这样的,在父div中有可以拖动的子div,然后给父div添加transform:scale(0.5)进行缩放后,鼠标拖动子div的速度也变成了0.5倍,相当于鼠标拖动了200px,但是div只移动到100px的位置。请问该如何修改代码,才能让缩放后的div拖动速度跟鼠标移动速度一致。搜了一下好像是要乘一个偏移量,但是找不到具体的方案
drag:(el,binding,vnode) =>{ // 可就在里写指令的js代码
const oDiv = el // 当前元素
document.onselectstart = () => {
return false
}
oDiv.onmousedown = e => {
let divHeight = e.target.clientHeight
let divWidth = e.target.clientWidth
// 鼠标按下,计算当前元素距离可视区的距离
let disX = e.clientX - oDiv.offsetLeft
let disY = e.clientY - oDiv.offsetTop
document.onmousemove = e => {
let l = e.clientX - disX
let t = e.clientY - disY
oDiv.style.left = that.formDataList[id].x + 'px'
oDiv.style.top = that.formDataList[id].y + 'px'
}
document.onmouseup = e => {
document.onmousemove = null
document.onmouseup = null
}
return false
}
},