Vue+js realizes video fade-in and fade-out effect

Vue+js realizes video fade-in and fade-out effect

Vue+js realizes the fade in and fade out of the video, for your reference, the specific content is as follows

A simple video fade-in and fade-out effect is shown in the figure

The editor directly posted the code. If you are interested, you can copy and run it. Thank you

<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()">Play</el-button>
      <el-button type="primary" @click="pause()">Pause</el-button>
      <el-button type="primary" @click="fadeIn(100)">Fade in</el-button>
      <el-button type="primary" @click="fadeOut(100)">Fade out</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>

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Simple implementation of fading in and out of Vue routing switching
  • An example of making background fade-in and fade-out switching animation with vuejs

<<:  A brief analysis of the tutorial on installing MySQL 8.0.18 on CentOS 6.8 (RPM method)

>>:  How to shut down/restart/start nginx

Recommend

JavaScript to filter arrays

This article example shares the specific code for...

Simple CSS text animation effect

Achieve results Implementation Code html <div ...

JS 9 Promise Interview Questions

Table of contents 1. Multiple .catch 2. Multiple ...

How to use history redirection in React Router

In react-router, the jump in the component can be...

Discussion on the Issues of Image Button Submission and Form Repeated Submission

In many cases, in order to beautify the form, the ...

Teach you how to monitor Tomcat's JVM memory through JConsoler

Table of contents 1. How to monitor Tomcat 2. Jav...

Detailed tutorial on using the Prettier Code plugin in vscode

Why use prettier? In large companies, front-end d...

Detailed explanation of how Vue components transfer values ​​to each other

Table of contents Overview 1. Parent component pa...

Detailed explanation of Angular data binding and its implementation

Table of contents Preface What is data binding? T...

Mysql implements null value first/last method example

Preface We already know that MySQL uses the SQL S...

Vue: Detailed explanation of memory leaks

What is a memory leak? A memory leak means that a...

Detailed explanation of MySQL information_schema database

1. Overview The information_schema database is th...

CSS modular solution

There are probably as many modular solutions for ...