zoukankan      html  css  js  c++  java
  • vue组件实现查看大图效果

    使用的index.vue代码

    <template>
        <img :src="imgUrl" @click="clickImg($event)">
        <big-img v-if="showImg" @clickit="viewImg" :imgSrc="imgSrc"></big-img>
    </template>
    import BigImg from '../../components/imgView.vue'
    export default {
        components: {
          'big-img': BigImg
        },
        methods: {
          clickImg (e) {
            this.showImg = true
            this.imgSrc = e.currentTarget.src
          },
          viewImg () {
            this.showImg = false
          }
        }
    }    

    组件的代码:

    <template>
        <!-- 过渡动画 -->
        <transition name="fade">
            <div class="img-view" @click="bigImg">
                <!-- 遮罩层 -->
                <div class="img-layer"></div>
                <div class="img">
                    <img :src="imgSrc">
                </div>
            </div>
        </transition>
    </template>
    <script>
    export default {
      props: ['imgSrc'],
      methods: {
        bigImg () {
            // 发送事件
          this.$emit('clickit')
        }
      }
    }
    </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: absolute;
        top: 0px;
         100%;
        height: 100%;
    }
    
    /*遮罩层样式*/
    .img-view .img-layer {
        position: fixed;
        z-index: 999;
        top: 0;
        left: 0;
        background: rgba(0, 0, 0, 0.7);
         100%;
        height: 100%;
        overflow: hidden;
    }
    
    /*不限制图片大小,实现居中*/
    .img-view .img img {
        max- 100%;
        display: block;
        position: fixed;
         26%;
        /*height: 80%;*/
        top: 50%;
        left: 50%;
        transform: translate(-50%,-50%);
        margin: auto;
        z-index: 1000;
    }
    </style>
  • 相关阅读:
    27. Remove Element
    26. Remove Duplicates from Sorted Array
    643. Maximum Average Subarray I
    674. Longest Continuous Increasing Subsequence
    1. Two Sum
    217. Contains Duplicate
    448. Find All Numbers Disappeared in an Array
    566. Reshape the Matrix
    628. Maximum Product of Three Numbers
    UVa 1349 Optimal Bus Route Design (最佳完美匹配)
  • 原文地址:https://www.cnblogs.com/qq364735538/p/7338858.html
Copyright © 2011-2022 走看看