vue css 拖拽,vue----拖拽小方块
话不多说,直接来实例1.html代码如下:2.css样式如下:div.box1{width:100px; height:100px; background:red; position:absolute; top:0;left:0; cursor:move;} div.box2{width:100px; height:100px; background:blue; position:absolute
话不多说,直接来实例
1.html代码如下:
2.css样式如下:
div.box1{width:100px; height:100px; background:red; position:absolute; top:0;left:0; cursor:move;} div.box2{width:100px; height:100px; background:blue; position:absolute; top:0;right:0; cursor:move;}
3.vue代码如下:
Vue.directive('drag',function(){ var oDiv=this.el; oDiv.onmousedown=function(ev){ var disX=ev.clientX-oDiv.offsetLeft; var disY=ev.clientY-oDiv.offsetTop; document.onmousemove=function(ev){ var l=ev.clientX-disX; var t=ev.clientY-disY; oDiv.style.left=l+'px'; oDiv.style.top=t+'px'; }; document.onmouseup=function(){ document.onmousemove=document.onmouseup=null; }; } }) window.onload=function(){ var vm=new Vue({ data:{ }, methods:{ } }).$mount('#box');//手动挂载!! };
更多推荐




所有评论(0)