// 拖拽自定义指令添加
Vue.directive('drag', {
bind(el){
let disX = 0;
let disY = 0;
let isDragStart = false;
el.addEventListener('mousedown', e => {
disX = e.clientX - el.offsetLeft;
disY = e.clientY - el.offsetTop;
isDragStart = true;
e.preventDefault();
});
document.addEventListener('mousemove', e => {
if(isDragStart) {
let x = e.clientX - disX;
let y = e.clientY - disY;
el.style.left = x + 'px';
el.style.top = y + 'px';
}
});
document.addEventListener('mouseup', e => {
isDragStart = false;
});
}
});
版权声明:本文为qq_34870529原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。