溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Vue登錄主頁動態(tài)背景短視頻制作

發(fā)布時間:2020-09-25 14:56:25 來源:腳本之家 閱讀:496 作者:`花花` 欄目:web開發(fā)

本文實例為大家分享了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 : class="filter">
   <!--內(nèi)容-->
  </div>
  <video : 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 : 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動畫了。

Vue登錄主頁動態(tài)背景短視頻制作

五、HTML版

視頻呢下載和html版代碼在官網(wǎng)最下方:https://coverr.co

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持億速云。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI