前端實(shí)現(xiàn)視頻Banner+滾屏視頻效果圖及代碼
視頻Banner
效果圖:

貼代碼:
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>視頻 Banner 示例</title>
<style>
body,
html {
margin: 0;
padding: 0;
height: 100%;
overflow-x: hidden;
}
.video-banner {
position: relative;
width: 100%;
height: 100vh;
overflow: hidden;
}
#video-background {
position: absolute;
top: 50%;
left: 50%;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
z-index: -1;
transform: translate(-50%, -50%);
}
.video-content {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
color: white;
z-index: 1;
}
.video-content h1 {
font-size: 3em;
margin: 0;
}
.video-content p {
font-size: 1.5em;
margin: 10px 0 30px;
}
.video-content .btn {
display: inline-block;
padding: 10px 20px;
background-color: #662d91;
color: white;
text-decoration: none;
border-radius: 5px;
font-size: 1.2em;
transition: background-color 0.3s ease;
}
.video-content .btn:hover {
background-color: #50247a;
}
</style>
</head>
<body>
<header class="video-banner">
<video autoplay muted loop id="video-background">
<source src="./assets/1080p.mp4" type="video/mp4">
您的瀏覽器不支持 video 標(biāo)簽。
</video>
<div class="video-content">
<h1>歡迎來(lái)到立橋銀行</h1>
<p>立足港澳,橋連世界</p>
<a href="#more" rel="external nofollow" class="btn">了解更多</a>
</div>
</header>
</body>
</html>
滾屏視頻

貼代碼:
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>滾屏動(dòng)畫(huà)視頻示例</title>
<style>
body,
html {
margin: 0;
padding: 0;
height: 100%;
overflow: hidden;
font-family: Arial, sans-serif;
}
.scroll-video-container {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
overflow: hidden;
z-index: -1;
}
#scroll-video {
position: absolute;
top: 50%;
left: 50%;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
transform: translate(-50%, -50%);
object-fit: cover;
}
#content {
height: 1000px;
/* 調(diào)整高度以適應(yīng)滾動(dòng) */
overflow-y: scroll;
scroll-behavior: smooth;
}
.section {
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
padding: 20px;
box-sizing: border-box;
}
.section h1 {
font-size: 3em;
margin: 0;
}
.section p {
font-size: 1.5em;
margin: 10px 0 30px;
}
</style>
</head>
<body>
<div class="scroll-video-container">
<video id="scroll-video" src="./assets/section-3-desktop-900-264-crf-20-g-1.mp4" muted></video>
</div>
<section id="content">
<div class="section" id="section1">
<h1>歡迎來(lái)到立橋銀行</h1>
<p>立足港澳,橋連世界</p>
</div>
<div class="section" id="section2">
<h1>我們的服務(wù)</h1>
<p>提供多種金融服務(wù),滿足您的需求</p>
</div>
<div class="section" id="section3">
<h1>聯(lián)系我們</h1>
<p>了解更多詳情,請(qǐng)聯(lián)系我們</p>
</div>
</section>
<script>
document.addEventListener('DOMContentLoaded', () => {
const video = document.getElementById('scroll-video');
const content = document.getElementById('content');
const totalHeight = content.scrollHeight - window.innerHeight;
let lastScrollTop = 0;
let timeoutId;
content.addEventListener('scroll', () => {
const scrollPosition = content.scrollTop / totalHeight;
const videoDuration = video.duration;
const currentTime = scrollPosition * videoDuration;
// 播放視頻
video.currentTime = currentTime;
video.play();
// 清除之前的定時(shí)器
clearTimeout(timeoutId);
// 設(shè)置一個(gè)新的定時(shí)器,在用戶停止?jié)L動(dòng)后暫停視頻
timeoutId = setTimeout(() => {
video.pause();
}, 100); // 100毫秒后暫停視頻
});
});
</script>
</body>
</html>
總結(jié)
到此這篇關(guān)于前端實(shí)現(xiàn)視頻Banner+滾屏視頻效果圖及代碼的文章就介紹到這了,更多相關(guān)前端實(shí)現(xiàn)視頻Banner內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
JavaScript編程的10個(gè)實(shí)用小技巧
盡管我使用Javascript來(lái)做開(kāi)發(fā)有很多年了,但它常有一些讓我很驚訝的小特性。對(duì)于我來(lái)說(shuō),Javascript是需要持續(xù)不斷的學(xué)習(xí)的。2014-04-04
javascript 另一種圖片滾動(dòng)切換效果思路
把圖片們用ul之類的包起來(lái),并設(shè)置float。然后設(shè)置這個(gè)ul本身為absolute定位,其父標(biāo)簽用relative定位。通過(guò)設(shè)置ul的left或top值,實(shí)現(xiàn)圖片隊(duì)列的滾動(dòng)效果2012-04-04
原生js提示框并自動(dòng)關(guān)閉(手工關(guān)閉)
今天在寫后臺(tái)交互的時(shí)候原來(lái)都是用alert太難看每次都需要點(diǎn)擊一下才可以,比較麻煩所以特整理了幾個(gè)比較好的js提示框代碼,方便提示一下2023-04-04
詳解JavaScript設(shè)計(jì)模式中的享元模式
享元模式是一種用于性能優(yōu)化的模式。享元模式的核心是運(yùn)用共享技術(shù)來(lái)有效支持大量細(xì)粒度的對(duì)象.如果系統(tǒng)中創(chuàng)建了大量類似的對(duì)象而導(dǎo)致內(nèi)存占用過(guò)高,本文通過(guò)介紹書(shū)中文件上傳的優(yōu)化案例來(lái)說(shuō)明享元模式的使用方式和作用,需要的朋友可以參考下2023-06-06
JavaScript 浮點(diǎn)數(shù)運(yùn)算 精度問(wèn)題
JavaScript小數(shù)在做四則運(yùn)算時(shí),精度會(huì)丟失,這會(huì)在項(xiàng)目中引起諸多不便,先請(qǐng)看下面腳本。2009-10-10
javascript IFrame 強(qiáng)制刷新代碼
經(jīng)常會(huì)使用多個(gè)iframe來(lái)展示領(lǐng)域模型主子關(guān)系(主/子單),測(cè)試發(fā)現(xiàn)iframe是有cache功能的2009-07-07

