如何循环播放背景视频并删除控件,同时仍保留随机背景视频?



所以我让我的视频成为我的背景,脚本在加载或更新时刷新。

每当我启动我的网站时,我都可以看到视频的控件不到一秒钟,然后视频播放。

如何删除它并使我的视频循环播放?

此外,当您在视频结束后zoom out页面上时,您可以看到控件。我将在底部包含屏幕截图。

如果需要,我可以提供一个指向我的网站的链接,您可以在其中看到我在说什么。请告诉我。

.video-background {
background: #000;
position: fixed;
top: 0; right: 0; bottom: 0; left: 0;
overflow: hidden;
z-index: -100;
pointer-events: none;
}
.video-foreground,
.video-background iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
}
#vidtop-content {
	top: 0;
	color: #fff;
}
.vid-info { position: absolute; top: 0; right: 0; width: 33%; background: rgba(0,0,0,0.3); color: #fff; padding: 1rem; font-family: Avenir, Helvetica, sans-serif; }
.vid-info h1 { font-size: 2rem; font-weight: 700; margin-top: 0; line-height: 1.2; }
.vid-info a { display: block; color: #fff; text-decoration: none; background: rgba(0,0,0,0.5); transition: .6s background; border-bottom: none; margin: 1rem auto; text-align: center; }
@media (min-aspect-ratio: 16/9) {
.video-foreground { height: 300%; top: -100%; }
}
@media (max-aspect-ratio: 16/9) {
.video-foreground { width: 300%; left: -100%; }
}
@media all and (max-width: 600px) {
.vid-info { width: 50%; padding: .5rem; }
.vid-info h1 { margin-bottom: .2rem; }
}
@media all and (max-width: 500px) {
.vid-info .acronym { display: none; }
}
	    <script>
var videos = ["./Videos/1.mp4", "./Videos/2.mp4", "./Videos/3.mp4", "./Videos/4.mp4"];
window.onload = function () {
var playerDiv = document.getElementById("random_player");
var player = document.createElement("IFRAME");
var randomVideoUrl = videos[Math.floor(Math.random() * videos.length)];
player.setAttribute('width', '100%');
player.setAttribute('height', '100%');
player.setAttribute('src', randomVideoUrl);
playerDiv.appendChild(player);
};
</script>

<div class="video-background">
<div class="video-foreground">
<div id="random_player" />
</div>
</div>
	

截图

删除控件:

player.controls = false;

循环播放:

player.addEventListener('ended', function() {
this.currentTime = 0;
this.play();
}, false);
player.play();

但我看到你正在将它加载到iframe中。为什么?你为什么不简单地使用视频HTML元素?它会是这样的:

window.onload = function () {
var playerDiv = document.getElementById('random_player');
var player = document.createElement('video');
var sourceVideo = document.createElement('source');
var randomVideoUrl = videos[Math.floor(Math.random() * videos.length)];
player.setAttribute('width', '100%');
player.setAttribute('height', '100%');
sourceVideo.setAttribute('src', randomVideoUrl);
playerDiv.appendChild(player);
player.appendChild(sourceVideo);
player.controls = false;
player.addEventListener('ended', function () {
this.currentTime = 0;
this.play();
}, false);
player.play();
};

最新更新