Vue登录主页动态背景短视频制作

 更新时间:2019年09月21日 08:29:09   作者:`花花`  
这篇文章主要为大家详细介绍了Vue登录主页动态背景短视频的制作方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了Vue制作登录主页动态背景短视频的具体代码,供大家参考,具体内容如下

一、HTML代码

<source src="../assets/video/G1s.mp4" type="video/mp4"/>

注:src的路径根据自己的需要改变;

video标签无法自动播放 刷新后无法自动播放;

解决方法:给video标签添加muted属性,可写为muted或完整写法:muted=“muted”

<template>
 <div class="homepage-hero-module">
  <div class="video-container">
  <div :style="fixStyle" class="filter">
   <!--内容-->
  </div>
  <video :style="fixStyle" autoplay loop muted class="fillWidth" v-on:canplay="canplay">
   <source src="../assets/video/G1s.mp4" type="video/mp4"/>
   浏览器不支持 video 标签,建议升级浏览器。
   <source src="../assets/video/G1w.webm" type="video/webm"/>
   浏览器不支持 video 标签,建议升级浏览器。
  </video>
  <div class="poster hidden" v-if="!vedioCanPlay">
   <img :style="fixStyle" src="../assets/video/G1.jpg" alt="">
  </div>
  </div>
 </div>
</template>

二、css代码

<style scoped>
 .homepage-hero-module,
 .video-container {
 position: relative;
 height: 100vh;
 overflow: hidden;
 }
 
 .video-container .poster img{
 z-index: 0;
 position: absolute;
 }
 
 .video-container .filter {
 z-index: 1;
 position: absolute;
 background: rgba(0, 0, 0, 0.4);
 width: 100%;
 }
 
 .fillWidth {
 width: 100%;
 }
</style>

三、JavaScript----代码

name: '  ***  '   自定义

export default {
 name: 'Video',
 data() {
  return {
  vedioCanPlay: false,
  fixStyle: ''
  }
 },
 methods: {
  canplay() {
  this.vedioCanPlay = true
  }
 },
 mounted: function() { //屏幕自适应
  window.onresize = () => {
  const windowWidth = document.body.clientWidth
  const windowHeight = document.body.clientHeight
  const windowAspectRatio = windowHeight / windowWidth
  let videoWidth
  let videoHeight
  if (windowAspectRatio < 0.5625) {
   videoWidth = windowWidth
   videoHeight = videoWidth * 0.5625
   this.fixStyle = {
   height: windowWidth * 0.5625 + 'px',
   width: windowWidth + 'px',
   'margin-bottom': (windowHeight - videoHeight) / 2 + 'px',
   'margin-left': 'initial'
   }
  } else {
   videoHeight = windowHeight
   videoWidth = videoHeight / 0.5625
   this.fixStyle = {
   height: windowHeight + 'px',
   width: windowHeight / 0.5625 + 'px',
   'margin-left': (windowWidth - videoWidth) / 2 + 'px',
   'margin-bottom': 'initial'
   }
  }
  }
  window.onresize()
 }
 }

四、效果演示

由于上传大小限制,只能剪短的gif动画了。

五、HTML版

视频呢下载和html版代码在官网最下方:https://coverr.co

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关文章

  • 在vue react中如何使用Web Components组件

    在vue react中如何使用Web Components组件

    这篇文章主要介绍了在vue react中如何使用Web Components组件问题,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2023-05-05
  • 教你在vue 中使用 svg symbols

    教你在vue 中使用 svg symbols

    这篇文章主要介绍了如何在 vue 中使用 svg symbols,本文通过示例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2022-08-08
  • 基于vue2.0实现的级联选择器

    基于vue2.0实现的级联选择器

    这篇文章主要介绍了基于vue2.0实现的级联选择器,基于Vue的级联选择器,可以单项,二级, 三级级联,多级级联,有兴趣可以了解一下
    2017-06-06
  • vue.js指令v-for使用及索引获取

    vue.js指令v-for使用及索引获取

    这篇文章主要为大家详细介绍了vue.js中v-for使用及索引获取,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2016-11-11
  • 如何解决element-ui中多个table在tab切换时出现宽度缩小问题

    如何解决element-ui中多个table在tab切换时出现宽度缩小问题

    这篇文章主要介绍了如何解决element-ui中多个table在tab切换时出现宽度缩小问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2023-10-10
  • Vue3 计算属性的用法详解

    Vue3 计算属性的用法详解

    学过 vue2 的宝子们应该都清楚,计算属性这个东西在项目开发过程中使用的还是比较频繁的,使用频率相对来说比较高。本文就来为大家介绍一下Vue3中计算属性的用法,需要的可以参考一下
    2022-07-07
  • vue时间转换的几种方式

    vue时间转换的几种方式

    这篇文章主要介绍了vue时间转换的几种方式,需要的朋友可以参考下
    2022-05-05
  • Vue表单控件数据绑定方法详解

    Vue表单控件数据绑定方法详解

    本文将详细介绍Vue表单控件数据绑定方法,需要的朋友可以参考下
    2020-02-02
  • Vue使用distpicker插件实现省市级下拉框三级联动

    Vue使用distpicker插件实现省市级下拉框三级联动

    这篇文章主要介绍了Vue使用distpicker插件实现省市级下拉框三级联动,比如通过JSON文件生成对应的区域下拉框,element-china-are插件,包括distpicker插件,通过代码讲解如何使用distpicker插件实现省市级三联跳动,需要的朋友可以参考下
    2023-02-02
  • vue axios同步请求解决方案

    vue axios同步请求解决方案

    这篇文章主要介绍了vue axios同步请求解决方案,需要的朋友可以参考下
    2017-09-09

最新评论