vue添加旋转图⽚修改csstransform值//点击放⼤图⽚并旋转图⽚
conponents组建
<template>
<!-- 过渡动画 -->
<transition name="fade">
<div class="img-view" @click="bigImg">
<!-- 遮罩层 -->
<div class="img-layer">
<div class="imgBox">
<div >
<img :src="imgSrc" :>
</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()" >
<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="/files/12708/image-with-title.png" @click="clickImg($event)" width="100" height="100" >
<!-- 放⼤图⽚ -->
svg图片怎么使用
<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;
},
  }
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。