drag 自定义指令
作者:互联网
import Vue from 'vue'
const drag = Vue.directive('drag', { bind: function(el) {}, inserted: function(el) { el.onmousedown = function(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.onmousemove = document.onmouseup = null } } }, updated: function(el) {}, }) export default drag
const drag = Vue.directive('drag', { bind: function(el) {}, inserted: function(el) { el.onmousedown = function(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.onmousemove = document.onmouseup = null } } }, updated: function(el) {}, }) export default drag
标签:function,el,自定义,disx,disy,drag,指令,document 来源: https://www.cnblogs.com/chenlongsheng/p/16673127.html