Vue登錄主頁動態(tài)背景短視頻制作
本文實例為大家分享了Vue制作登錄主頁動態(tài)背景短視頻的具體代碼,供大家參考,具體內(nèi)容如下
一、HTML代碼
<source src="../assets/video/G1s.mp4" type="video/mp4"/>
注:src的路徑根據(jù)自己的需要改變;
video標(biāo)簽無法自動播放 刷新后無法自動播放;
解決方法:給video標(biāo)簽添加muted屬性,可寫為muted或完整寫法:muted=“muted”
<template> <div class="homepage-hero-module"> <div class="video-container"> <div :style="fixStyle" class="filter"> <!--內(nèi)容--> </div> <video :style="fixStyle" autoplay loop muted class="fillWidth" v-on:canplay="canplay"> <source src="../assets/video/G1s.mp4" type="video/mp4"/> 瀏覽器不支持 video 標(biāo)簽,建議升級瀏覽器。 <source src="../assets/video/G1w.webm" type="video/webm"/> 瀏覽器不支持 video 標(biāo)簽,建議升級瀏覽器。 </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() { //屏幕自適應(yīng) 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版代碼在官網(wǎng)最下方:https://coverr.co
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vue中使用echarts實現(xiàn)繪制人體動態(tài)圖
這篇文章主要為大家詳細(xì)介紹了Vue中如何使用echarts實現(xiàn)繪制人體動態(tài)圖,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-03-03利用vite創(chuàng)建vue3項目的全過程及一個小BUG詳解
Vite作為一個構(gòu)建工具,提供了一種快速的方法來構(gòu)建Vue應(yīng)用,而Vue3?則是一個前端框架,提供了強大的功能來構(gòu)建和管理前端項目,下面這篇文章主要給大家介紹了關(guān)于利用vite創(chuàng)建vue3項目的全過程及一個小BUG的相關(guān)資料,需要的朋友可以參考下2023-04-04antd中table展開行默認(rèn)展示,且不需要前邊的加號操作
這篇文章主要介紹了antd中table展開行默認(rèn)展示,且不需要前邊的加號操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-11-11vue使用axios實現(xiàn)動態(tài)追加數(shù)據(jù)
在vuejs中使用axios時,有時候需要追加數(shù)據(jù),比如,移動端下拉觸底加載,分頁加載,滑動滾動條等,下面小編就來為大家介紹一下如何使用使用axios實現(xiàn)動態(tài)追加數(shù)據(jù)吧2023-10-10vue使用video.js實現(xiàn)播放m3u8格式的視頻
這篇文章主要為大家詳細(xì)介紹了vue如何使用video.js實現(xiàn)播放m3u8格式的視頻,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2023-12-12vue-calendar-component 封裝多日期選擇組件的實例代碼
這篇文章主要介紹了vue-calendar-component 封裝多日期選擇組件,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-12-12基于vue-router的matched實現(xiàn)面包屑功能
本文主要介紹了基于vue-router的matched實現(xiàn)面包屑功能,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-09-09