vue中怎么实现图片放大缩小的按键功能并可拖曳
Admin 2022-07-02 群英技术资讯 1261 次浏览
这篇文章给大家介绍了“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进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
这篇文章主要介绍了react实现浏览器自动刷新的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
在Node.js中使用在Typescript中使用在Deno中使用3.APIParamMap:具有字符串键的对象urlcat:构建完整的 URLquery:构建查询字符串subst:替换路径参数join:使用
vue Element左侧无限级菜单怎么实现?最近项目中,要用到element-ui的无限级分类菜单,根据角色生成不同的递归数据,查阅了网上很多资料,发现很多都不太完整并且没有很多的延伸性。
这篇文章我们来了解jQuery获得与失去焦点事件的方法,在网站中如果存在一些让用户填写内容的表单元素,那么我们能通过焦点事件和失去焦点事件,来给用户作出一些提示的内容。那么jQuery是如何实现获得与失去焦点事件的呢?接下来就跟随小编来一起学习一下吧!
vue用@表示src文件夹,引入时找文件路径更方便,下面这篇文章主要给大家介绍了关于vue配置根目录(用@代表src目录)的相关资料,文中通过示例代码介绍的非常详细,需要的朋友可以参考下
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
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