vue中怎么实现图片放大缩小的按键功能并可拖曳
Admin 2022-07-02 群英技术资讯 1148 次浏览
这篇文章给大家介绍了“vue中怎么实现图片放大缩小的按键功能并可拖曳”的相关知识,讲解详细,步骤过程清晰,有一定的借鉴学习价值,因此分享给大家做个参考,感兴趣的朋友接下来一起跟随小编看看吧。vue图片拖拉转放大缩小组件的具体使用方法,供大家参考,具体内容如下
<doc>
图片组件 - 用户放大缩小以及拖拽
</doc>
<template>
<div style="width: 100%;position: relative;overflow: hidden;text-align: center;border: 1px solid #f1f2f3;">
<el-button size='mini' @click="toBIgChange" icon="el-icon-zoom-in"
style="position: absolute;top: 2px ;left: 2px;z-index: 999;"></el-button>
<el-button size='mini' @click="toSmallChange" icon="el-icon-zoom-out"
style="position: absolute;top: 2px ;left: 40px;z-index: 999;"></el-button>
<img id="img" :src="src" alt="" @mousedown.prevent="dropImage" :style="{transform:'scale('+multiples+')'}">
</div>
</template>
<script>
export default {
props: ['src'],
data() {
return {
multiples: 1,
odiv: null,
}
},
mounted() {
this.dropImage()
},
watch: {
src(newValue, oldValue) {
this.multiples = 1
if (this.odiv !== null) {
this.odiv.style.left = '0px';
this.odiv.style.top = '0px';
}
},
},
methods: {
toBIgChange() {
if (this.multiples >= 2) {
return;
}
this.multiples += 0.25;
},
// 缩小
toSmallChange() {
if (this.multiples <= 1) {
return;
}
this.multiples -= 0.25;
},
// 拖拽
dropImage(e) {
if (e === null) {
return
}
this.odiv = e.target; //获取目标元素
//算出鼠标相对元素的位置
let disX = e.clientX - this.odiv.offsetLeft;
let disY = e.clientY - this.odiv.offsetTop;
document.onmousemove = (e) => { //鼠标按下并移动的事件
//用鼠标的位置减去鼠标相对元素的位置,得到元素的位置
let left = e.clientX - disX;
let top = e.clientY - disY;
//绑定元素位置到positionX和positionY上面
this.positionX = top;
this.positionY = left;
//移动当前元素
this.odiv.style.left = left + 'px';
this.odiv.style.top = top + 'px';
};
document.onmouseup = (e) => {
document.onmousemove = null;
document.onmouseup = null;
};
},
}
}
</script>
<style scoped>
img {
width: 100%;
position: relative;
}
</style>

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
微信小程序实现上传视频功能 本文实例为大家分享了微信小程序上传视频,供大家参考,具体内容如下 微信开发者工具需要安装ffmpeg环境才能正常使用下面的官方方法. 1.调用官方提供的方法(wx.chooseMedia) choosevideo(){ let that=this console.log("上传视频的方法") wx.chooseMedia({ count: 1, //上传视频的个数 mediaType:['video'], //限制上传的类型 ...
本文主要介绍了React组件通信之路由传参(react-router-dom),文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
这篇文章主要为大家详细介绍了Javascript实现关闭广告效果,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
去除第一个元素的方法:1、利用“eq(0)”选择器和remove()方法,语法“$("元素").eq(0).remove()”;2、利用“:first”选择器和remove()方法,语法“$("元素:first").remove()”。
这篇文章主要为大家详细介绍了原生JS实现分享侧边栏,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 ICP核准(ICP备案)粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008