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