Vue登录主页动态背景短视频制作
2019-11-04 18:06
4591 查看
本文实例为大家分享了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.js 2.0 酷炫自适应背景视频登录页面实现方式
- 用duilib制作仿QQ2013动态背景登录器
- android 仿QQ动态登录背景、视频背景
- 原创安卓手机QQ7.0登录界面动态背景视频实现方案
- Android 仿QQ动态背景登录,Android用视频做背景的轻松实现
- 基于 Vue.js 2.0 酷炫自适应背景视频登录页面的设计
- 用duilib制作仿QQ2013动态背景登录器
- 用duilib制作仿QQ2013动态背景登录器
- Android视频背景,动态背景,Android用视频做背景的轻松实现
- Dreamweaver MX 2004制作ASP动态网站高清视频教程
- 针对无人机航拍视频中动态背景下的目标检测
- Matlab制作视频并转换成gif动态图的两种方法
- vue单页应用中动态添加背景图片
- Android 视频背景,视频背景登录
- vue 手机端无法播放动态加载的视频
- ASP.NET动态网站开发培训-24.论文管理系统(四、制作Login页面和后台论文管理主页)
- 如何使用jQuery 制作全屏幕背景的嵌入视频
- 基于CSS3动态背景登录框代码
- 模仿手机QQ以视频流背景的登录界面
- vue动态改变背景图片demo分享