vue+js实现视频淡入淡出效果
更新时间:2021年08月13日 17:28:59 作者:aminsky0
这篇文章主要为大家详细介绍了vue+js实现视频的淡入淡出,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
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>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
相关文章
解决VUE mounted 钩子函数执行时 img 未加载导致页面布局的问题
这篇文章主要介绍了解决VUE mounted 钩子函数执行时 img 未加载导致页面布局的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2020-07-07
解决vue-cli@3.xx安装不成功的问题及搭建ts-vue项目
这篇文章主要介绍了解决vue-cli@3.xx安装不成功的问题及搭建ts-vue项目.文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2020-02-02


最新评论