vue 添加旋转图片 修改css transform 值
//点击放大图片并旋转图片
conponents组建
<template>
<!-- 过渡动画 -->
<transition name="fade">
<div class="img-view" @click="bigImg">
<!-- 遮罩层 -->
<div class="img-layer">
<div class="imgBox">
<div style="width: 400px;height: 400px;margin-bottom: 20px;">
<img :src="imgSrc" :style="{transform:'rotateZ('+deg+'deg)'}">
</div>
<div class="rotateBox">
<el-button type="primary" @click.stop="fan()">
<svg-icon icon-class="zuoRotate" />
逆时针旋转
</el-button>
<el-button type="primary" @click.stop="zheng()" style="margin-left:20px ;">
<svg-icon icon-class="youRotate" />
顺时针旋转
</el-button>
</div>
</div>
</div>
</div>
</transition>
</template>
<script>
export default {
props: ['imgSrc'],
data(){
return{
deg:0,
}
},
methods: {
bigImg() {
// 发送事件
this.$emit('clickit')
},
fan(){
this.deg -= 90;
if(this.deg >= 360){
this.deg = 0
}
},
zheng(){
this.deg += 90;
if(this.deg >= 360){
this.deg = 0
}
}
}
}
</script>
<style scoped>
/*动画*/
.fade-enter-active,
.fade-leave-active {
transition: all .2s linear;
transform: translate3D(0, 0, 0);
}
.fade-enter,
.fade-leave-active {
transform: translate3D(100%, 0, 0);
}
/* bigimg */
.img-view {
position: relative;
width: 100%;
height: 100%;
}
/*遮罩层样式*/
.img-view .img-layer {
position: fixed;
z-index: 999;
top: 0;
left: 0;
background: rgba(0, 0, 0, 0.7);
width: 100%;
height: 100%;
overflow: hidden;
}
/*不限制图片大小,实现居中*/
.img-view .imgBox {
position: absolute;
left: calc(50% - 250px);
top: 100px;
width: 400px;
height: auto;
max-width: 100%;
max-height: 400px;
}
.img-view .imgBox img {
display: block;
width:400px;
height: auto;
max-width: 100%;
max-height: 400px;
margin: auto;
z-index: 1000;
margin-bottom: 10px;
}
.img-view .imgBox .rotateBox {
text-align: center;
}
</style>
使用:
<img src="https://mdn.mozillademos.org/files/12708/image-with-title.png" @click="clickImg($event)" width="100" height="100" style="margin-left: 120px;">
<!-- 放大图片 -->
<big-imgrotate v-if="showImg" @clickit="closeBigImg" :imgSrc="imgSrc"></big-imgrotate>
import BigImg from '@/components/bigImg_rotate/index.vue';
export default {
components: {
'big-imgrotate': BigImg
},
data() {
return {
showImg:false
}
},
methods: {
//点击放大图片
clickImg(e) {
this.showImg = true;
// 获取当前图片地址
this.imgSrc = e.currentTarget.src;
},
//关闭放大图片
closeBigImg(e) {
this.showImg = false;
},
}
}
vue 添加旋转图片 修改css transform 值的更多相关文章
- vue中如何实时修改输入的值
vue中如何实时修改输入的值 经常看到需要对用户输入的值进行实时修改,有时是需要修改为指定的展示内容,有时候是用来校验,禁止用户输入非法数据,总之是一个常见的需求吧,只是自己一直没有特意去关注.思来想 ...
- js 修改css属性值
js不能修改样式表 但是可以修改元素:比如 <div id="test" class="star-rating"></div> 对于上面 ...
- js修改css属性值
推荐用dom.style.setProperty('属性','属性值'); 例如: $("#id")[0].style.setProperty('margin-top','1px' ...
- vue打包后js和css、图片不显示,引用的字体找不到问题
vue打包后js和css.图片不显示,引用的字体找不到问题:图片一般都是背景图片. 一.vue打包出现js和css不显示问题: 1.不使用mode:'history' 2.使用mode:'histor ...
- css代码添加背景图片常用代码
css代码添加背景图片常用代码 1 背景颜色 { font-size: 16px; content: ""; display: block; width: 700px; heigh ...
- CSS transform旋转问题
我们都知道css的transform可以让旋转多少角度:transform:rotate(90deg),但是设置后只能旋转一次,如何想让它一直旋转下去怎么办?一种是使用matrix属性获取当前tran ...
- Sqlserver添加加字段、删除字段、修改字段类型、修改字段名、修改字段默认值
参考:https://www.cnblogs.com/pangpanghuan/p/6432331.html 初始化表: --.添加字段 --1.1.为null alter table DataTab ...
- vue项目中图片预览旋转功能
最近项目中需要在图片预览时,可以旋转图片预览,在网上找了下,发现有一款功能强大的图片组件:viewerjs. git-hup: https://github.com/fengyuanchen/view ...
- VUE项目中使用this.$forceUpdate();解决页面v-for中修改item属性值后页面v-if不改变的问题
VUE项目中使用this.$forceUpdate();解决页面v-for中修改item属性值后页面v-if不改变的问题:https://blog.csdn.net/jerrica/article/d ...
随机推荐
- verilog 之流水灯
1.黑金板 简易操作: 通过判断数值累加 个人观点:黑金代码质量有待提高,讲解不够详细 2.正点原子的 位置调换 led[:] <= {led[:],led[]}; 3.传统位移 led& ...
- eclipse maven工程打包失败
报错如下: Maven install失败 Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:comp ...
- 2018-2019-2-20175303 实验二 《Java开发环境的熟悉》实验报告
2018-2019-2-20175303 实验二 <Java开发环境的熟悉>实验报告 姓名:柴轩达 学号:20175303 班级:1753 实验课程:JAV ...
- JavaWeb的学习路线
JavaWeb的学习路线 一.BS结构 B/S结构(Browser/Server,浏览器/服务器模式),是WEB兴起后的一种网络结构模式,WEB浏览器是客户端最主要的应用软件.这种模式统一了客户端,将 ...
- vue项目打包之后js文件过大怎么办?
- Nginx 安装后 相关错误解决
1,安装 https://blog.csdn.net/wxyjuly/article/details/79443432 nobody 改为了 www /configure --user=www --g ...
- OI养老专题03:让坏人出列的约瑟夫问题
问题是这样的:一共有2n个人,其中有n个好人,n个坏人.好人的编号是1~n,坏人的编号是n+1~2n.要求你求出最小的m(报数到m的人出局),让前n个出局的人都是坏人. 似乎除了暴力,我们想不出其它的 ...
- Qt QDateEdit QDateTimeEdit
展示一个效果,然后附上一个“笑话~~”...回想起来都是搞笑的. 笑话来了,,,,几个月前,为了做出时间选择界面,我亲自“创造”了一个...今天发现了QDateEdit的属性CalendarPopup ...
- Canvas Snippets
========================================== Example: 1. To revel "fillStyle" property, type ...
- ubuntu16.04利用deb包安装mysql
https://blog.csdn.net/zht741322694/article/details/79013093