用 `
<video id="bgVideo" autoplay muted style="width:100%; height:100%; object-fit:cover; position:fixed; top:0; left:0; z-index:-1;">
<source src="bg.mp4" type="video/mp4">
</video>
<script>
const video = document.getElementById('bgVideo');
video.addEventListener('ended', () => {
// 1. 設置 body 背景圖
document.body.style.backgroundImage = "url('bg-end.jpg')";
document.body.style.backgroundSize = "cover";
document.body.style.backgroundPosition = "center";
// 2. 移除或隱藏 video 元素
video.remove(); // 或 video.style.display = 'none';
});
</script>
<video id="bgVideo" autoplay muted playsinline
style="width:100%; height:100%; object-fit:cover; position:fixed; top:0; left:0; z-index:-1;"
poster="bg-end.jpg">
<source src="bg.mp4" type="video/mp4">
</video>
關鍵屬性:
video.addEventListener('ended', () => {
video.currentTime = video.duration; // 跳到最後
video.pause(); // 暫停在最後一幀
// 可選:video.style.opacity = 1; 確保可見
});