vue自定义指令--拖拽

  directives:{
    drags(el){
      el.onmousedown=(e)=>{
        var disx=e.pageX-el.offsetLeft;
        var disy=e.pageY-el.offsetTop;
        document.onmousemove=(e)=>{
          el.style.left=e.pageX-disx+'px';
          el.style.top=e.pageY-disy+'px';
        }
        document.onmouseup=()=>{
          document.onmousedown = document.onmousemove = null
        }
        e.preventDefault();
      }
    }
  },

 

转载于:https://my.oschina.net/u/4099729/blog/3058890

你可能感兴趣的:(vue自定义指令--拖拽)