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 achieve floor effect

This article shares the specific code of JavaScri...

JS gets the position of the nth occurrence of a specified string in a string

Learn about similar methods for getting character...

vue front-end HbuliderEslint real-time verification automatic repair settings

Table of contents ESLint plugin installation in H...

Example code for implementing a simple search engine with MySQL

Table of contents Preface Introduction ngram full...

CentOS7 configuration Alibaba Cloud yum source method code

Open the centos yum folder Enter the command cd /...

JavaScript canvas Tetris game

Tetris is a very classic little game, and I also ...

How to align text boxes in multiple forms in HTML

The form code is as shown in the figure. The styl...

JavaScript method to detect the type of file

Table of contents 1. How to view the binary data ...

CentOS7 installation GUI interface and remote connection implementation

Use the browser (webdriver)-based selenium techno...

Detailed tutorial on using the Prettier Code plugin in vscode

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

Small program to implement a simple calculator

This article example shares the specific code of ...

GDB debugging MySQL actual combat source code compilation and installation

Download source code git clone https://github.com...

How to deploy code-server using docker

Pull the image # docker pull codercom/code-server...

5 Simple XHTML Web Forms for Web Design

Simple XHTML web form in web design 5. Technique ...

MySQL 8.0.11 MSI version installation and configuration graphic tutorial

This article shares the installation and configur...