video 动画自查 每次都是重新开始播放

        <div class="video-bg" @click="startVideo"></div>
        <div class="video-box" v-show="showSlide">
          <div class="overlay"></div>
          <div class="video" :class="{'slide':showSlide}">
            <span class="icon-close" @click="stopVideo"></span>
            <video ref="veo" src="https://cdn.cnbj1.fds.api.mi-img.com/product-images/mix4/video_show.mp4" controls="controls"></video>
          </div>
        </div>
  methods: {
    stopVideo () {
      this.showSlide = false
      this.$refs.veo.pause()
    },
    startVideo () {
      this.showSlide = true
      this.$refs.veo.currentTime = 0
      this.$refs.veo.play()
    }
  },
  data () {
    return {
      showSlide: false
    }
  }
        .video-bg{
          background:url('/imgs/product/gallery-1.png') no-repeat center;
          background-size:cover;
          width:1226px;
          height:540px;
          margin:0 auto 120px;
          cursor:pointer;
        }
        .video-box{
          .overlay {
            position: fixed;
            width: 100%;
            height: 100%;
            top: 0;
            left: 0;
            background-color: #333333;
            opacity: .4;
            z-index: 10;
          }
          .video{
            position:fixed;
            top:-50%;
            left:50%;
            transform:translate(-50%,-50%);
            z-index:10;
            width:1000px;
            height:536px;
            opacity:0;
            transition: all .6s;
            &.slide {
              top: 50%;
              opacity:1;
            }
            .icon-close {
              position:absolute;
              top:20px;
              right:20px;
              background:url('/imgs/icon-close.png') no-repeat center;
              width: 20px;
              height: 20px;
              cursor:pointer;
              z-index:11;
            }
            video{
              width:100%;
              height:100%;
              object-fit:cover; // 覆盖窗口
              outline:none;
            }
          }
        }

通过添加.slide 完成动画过度效果,用showSlide来控制是否显示

========================================================================

第二种实现方式 通过定义动画,添加拥有class让他具有运动的效果

        .video-bg{
          background:url('/imgs/product/gallery-1.png') no-repeat center;
          background-size:cover;
          width:1226px;
          height:540px;
          margin:0 auto 120px;
          cursor:pointer;
        }
        .video-box{
          .overlay {
            position: fixed;
            width: 100%;
            height: 100%;
            top: 0;
            left: 0;
            background-color: #333333;
            opacity: .4;
            z-index: 10;
          }
          @keyframes slideDown {
            from {
              top: -50%;
              opacity: 0;
            }
            to {
              top: 50%;
              opacity: 1;
            }
          }
          @keyframes slideUp {
            from {
              top: 50%;
              opacity: 1;
            }
            to {
              top: -50%;
              opacity: 0;
            }
          }
          .video{
            position:fixed;
            top:-50%;
            left:50%;
            transform:translate(-50%,-50%);
            z-index:10;
            width:1000px;
            height:536px;
            opacity: 1;
            &.slideDown {
              animation: slideDown .6s linear;
              top: 50%;
            }
            &.slideUp {
              animation: slideUp .6s linear;
            }
            .icon-close {
              position:absolute;
              top:20px;
              right:20px;
              background:url('/imgs/icon-close.png') no-repeat center;
              width: 20px;
              height: 20px;
              cursor:pointer;
              z-index:11;
            }
            video{
              width:100%;
              height:100%;
              object-fit:cover; // 覆盖窗口
              outline:none;
            }
          }
        }
  methods: {
    stopVideo () {
      this.showSlide = 'slideUp'
      this.$refs.veo.pause()
    },
    startVideo () {
      this.showSlide = 'slideDown'
      this.$refs.veo.currentTime = 0
      this.$refs.veo.play()
    }
  },
  data () {
    return {
      showSlide: ''
    }
  }
       <div class="video-bg" @click="startVideo"></div>
        <div class="video-box" v-show="showSlide">
          <div class="overlay"></div>
          <div class="video" :class="showSlide">
            <span class="icon-close" @click="stopVideo"></span>
            <video ref="veo" src="https://cdn.cnbj1.fds.api.mi-img.com/product-images/mix4/video_show.mp4" controls="controls"></video>
          </div>
        </div>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xiaodunmeng

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值