//点击放大图片并旋转图片

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 值的更多相关文章

  1. vue中如何实时修改输入的值

    vue中如何实时修改输入的值 经常看到需要对用户输入的值进行实时修改,有时是需要修改为指定的展示内容,有时候是用来校验,禁止用户输入非法数据,总之是一个常见的需求吧,只是自己一直没有特意去关注.思来想 ...

  2. js 修改css属性值

    js不能修改样式表 但是可以修改元素:比如 <div id="test" class="star-rating"></div> 对于上面 ...

  3. js修改css属性值

    推荐用dom.style.setProperty('属性','属性值'); 例如: $("#id")[0].style.setProperty('margin-top','1px' ...

  4. vue打包后js和css、图片不显示,引用的字体找不到问题

    vue打包后js和css.图片不显示,引用的字体找不到问题:图片一般都是背景图片. 一.vue打包出现js和css不显示问题: 1.不使用mode:'history' 2.使用mode:'histor ...

  5. css代码添加背景图片常用代码

    css代码添加背景图片常用代码 1 背景颜色 { font-size: 16px; content: ""; display: block; width: 700px; heigh ...

  6. CSS transform旋转问题

    我们都知道css的transform可以让旋转多少角度:transform:rotate(90deg),但是设置后只能旋转一次,如何想让它一直旋转下去怎么办?一种是使用matrix属性获取当前tran ...

  7. Sqlserver添加加字段、删除字段、修改字段类型、修改字段名、修改字段默认值

    参考:https://www.cnblogs.com/pangpanghuan/p/6432331.html 初始化表: --.添加字段 --1.1.为null alter table DataTab ...

  8. vue项目中图片预览旋转功能

    最近项目中需要在图片预览时,可以旋转图片预览,在网上找了下,发现有一款功能强大的图片组件:viewerjs. git-hup: https://github.com/fengyuanchen/view ...

  9. VUE项目中使用this.$forceUpdate();解决页面v-for中修改item属性值后页面v-if不改变的问题

    VUE项目中使用this.$forceUpdate();解决页面v-for中修改item属性值后页面v-if不改变的问题:https://blog.csdn.net/jerrica/article/d ...

随机推荐

  1. Android手机camera和IMU的标定

    https://qingsimon.github.io/post/2018-12-28-android%E6%89%8B%E6%9C%BA%E7%9B%B8camera%E5%92%8Cimu%E7% ...

  2. 【Python基础】lpthw - Exercise 39 字典

    1. 字典和列表的区别 对于列表,它是一些项的有序排列,只能通过数值来进行索引:对于字典,则可以通过许多东西进行索引,它采用键-值映射的方式,不存在一个特定的顺序,因此不能用类似列表的数值索引,但它的 ...

  3. 2019年春季学期第二周作业 基础作业 请在第一周作业的基础上,继续完成:找出给定的文件中数组的最大值及其对应的最小下标(下标从0开始)。并将最大值和对应的最小下标数值写入文件。 输入: 请建立以自己英文名字命名的txt文件,并输入数组元素数值,元素值之间用逗号分隔。 输出 在不删除原有文件内容的情况下,将最大值和对应的最小下标数值写入文件

    ~~~ include<stdio.h> include<stdlib.h> int main() { FILE*fp; int i=0,max=0,j=0,maxb=0; i ...

  4. poj1699

    #include<iostream> #include<cstring> using namespace std; ][]; ],len[],addlen[][]; int m ...

  5. Linux_磁盘分布_以及分区

    运用 Xshell  工具链接到你的服务器 1.     Fdisk -l    这是查看磁盘挂载列表情况 2.      Fdisk /dev/vdc   这是分区这个磁盘   m    是查看信息 ...

  6. docker的安装和升级

    1.删除docker sudo apt-get purge docker.io sudo rm -rf /etc/docker/ sudo apt-get autoremove 2. 安装docker ...

  7. vue框架与koa2服务器实现跨域通信

    首先我们在vue中引入axios, npm install axios --save 在需要用到的页面引入axios import axios from "axios"; 用axi ...

  8. dddquickly

    在项目开发最初的时候,他也有过一段狂欢般的快乐时光,不久之后,事情就越来越艰难. 项目的代码越来越难以维护,工作越来越像是一种煎熬,合作的同事对他越来越不满. “该是与这个项目,与这个公司说 bye ...

  9. 学习Makefile

    1> 编译一个文件2> 编译多个文件3> 编译多个目录下的文件4> inclue makefile5> 使用规则1>target:depend[tab]cmddep ...

  10. python练习题-day25

    class Person: __key=123 def __init__(self,username,password): self.username=username self.__password ...