vue+js实现视频的淡入淡出

9 篇文章 0 订阅

vue+js实现视频的淡入淡出

一个简单的视频淡入淡出效果如图

在这里插入图片描述

小编直接上代码了有兴趣可以拷贝运行一下,谢谢
<template>
  <div class="video-css">
    <div class="videocss" ref="videodom" style="background-color:black;">
      <video width="100%" ref="play" style="opacity: 1" :src="videoSrc2"></video>
    </div>
    <div class="video-but">
      <el-button type="primary" @click="play()">播放</el-button>
      <el-button type="primary" @click="pause()">暂停</el-button>
      <el-button type="primary" @click="fadeIn(100)">淡入</el-button>
      <el-button type="primary" @click="fadeOut(100)">淡出</el-button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      videoSrc: require('../../assets/web_1496003377.mp4'),
      videoSrc2: require('../../assets/video.mp4')
    }
  },
  methods: {
    play() {
      this.$refs.play.play()
    },
    pause() {
      this.$refs.play.pause()
    },
    fadeIn(speed) {
      let that = this
      var speed = speed || 30 ;
      var num = 0;
      var st = setInterval(function(){
        num++;
        that.$refs.play.style.opacity = num/10;
        if (num>=10) {  
          clearInterval(st);
        }
      }, speed);
    },
    fadeOut(speed) {
      let that = this
      var speed = speed || 30 ;
      var num = 10;
      var st = setInterval(function(){
        num--;
        that.$refs.play.style.opacity = num / 10 ;
        if (num<=0){ 
          clearInterval(st);
        }
      }, speed);
    }
  }
}
</script>

<style lang="less" scoped>
.video-css {
  .videocss {
    width: 800px;
    height: 450px;
    display: flex;
    justify-content: center;
  }
  .video-but {
    display: flex;
    margin-top: 20px;
    justify-content: flex-start;
    align-content: flex-start;
  }
}
</style>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值