穿网球裙的英语老师,首席新娘调包了,陈若琳
主要代码如下:
<template> <div id="test_3"> <img src="../assets/img/photo.jpg" @mousedown="start" @mouseup="stop" @mousemove="move" :style="style"> </div> </template> <script> export default{ data:function(){ return{ candrag: false, x0:0, y0:0, x1:0, y1:0, style:null } }, methods:{ start:function(e){ //鼠标左键点击 if(e.button==0){ this.candrag=true; //记录鼠标指针位置 this.x0=e.clientx; this.y0=e.clienty; } }, stop:function(e){ this.candrag=false; }, move:function(){ if(this.candrag==true){ this.x1=e.clientx; this.y1=e.clientx; let x=this.x1-this.x0; let y=this.y1-this.y0; let img=document.queryselector("#test_3 img"); this.style=`left:${img.offsetleft+x}px;top:${img.offsettop+y}px`; this.x0=this.x1; this.y0=this.y1; } } } } </script>
以上这篇vue.js实现图片的随意拖动方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
VUE+elementui组件在table-cell单元格中绘制微型echarts图
Vue通过getAction的finally来最大程度避免影响主数据呈现问题
vue 路由懒加载中给 Webpack Chunks 命名的方法
网友评论