图片放大功能

<img :src="backImage()" class="img" @click="clickImg($event)" />
<BigImage v-if="showImgS" @clickit="viewImg" :imgSrc="imgSrc"></BigImage>//图片放大组件

js方法:

clickImg:function(e){
  this.imgSrc = e.currentTarget.src;
  this.showImgS = true;
},

放大组件:

<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: fixed;
    z-index: 500;
    top: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.7);
    width: 100%;
    height: 100%;
    overflow: hidden;
  }

  /*遮罩层样式*/
  .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 {
    max-width: 100%;
     max-height: 70%;
    display: block;
    position: absolute;
     top:10%;
    left: 0;
    right: 0;
    margin: auto;
    z-index: 1000;
  }
</style>

猜你喜欢

转载自blog.csdn.net/qq_39692513/article/details/81454762
今日推荐