directives: {
drag: {
// 指令的定义 避免在边边挡住其他元素 添加一个自定义拖拽
bind: function(el) {
const oDiv = el; // 获取当前元素
el.style.pointerEvents = null
oDiv.onmousedown = (e) => {
const disX = e.clientX - oDiv.offsetLeft;
const disY = e.clientY - oDiv.offsetTop;
document.onmousemove = (e) => {
el.style.pointerEvents = 'none'
const left = e.clientX - disX;
const top = e.clientY - disY;
oDiv.style.left = left + 'px';
oDiv.style.top = top + 'px';
};
document.onmouseup = (e) => {
el.style.pointerEvents = null
document.onmousemove = null;
document.onmouseup = null;
}
}
}
}
},
关于拖动事件与点击事件冲突拖拽完触发了点击事件
于 2022-12-27 15:10:06 首次发布