html js css如何使循环混播放视频时视频切换很平滑的过渡

1.html代码

<video id="video1" autoplay loop muted playsinline>
  <source src="video1.mp4" type="video/mp4">
</video>
<video id="video2" autoplay loop muted playsinline>
  <source src="video2.mp4" type="video/mp4">
</video>
<!-- 其他视频... -->

2.css代码

video {
		     object-fit: fill;  
		}
  1. js代码
const videos = document.querySelectorAll('video');
let currentVideoIndex = 0;
 
function playNextVideo() {
  const currentVideo = videos[currentVideoIndex];
  currentVideo.addEventListener('ended', () => {
    currentVideo.style.display = 'none'; // 隐藏当前视频
    currentVideoIndex = (currentVideoIndex + 1) % videos.length; // 计算下一个视频的索引
    videos[currentVideoIndex].style.display = ''; // 显示下一个视频
    videos[currentVideoIndex].play(); // 播放下一个视频
  });
}
 
playNextVideo(); // 开始循环播放

最近更新

  1. TCP协议是安全的吗?

    2024-03-22 07:30:01       14 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-22 07:30:01       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-22 07:30:01       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-22 07:30:01       18 阅读

热门阅读

  1. 2024.3.21 ARM

    2024-03-22 07:30:01       17 阅读
  2. C++ 函数指针与回调函数

    2024-03-22 07:30:01       20 阅读
  3. 全球化战略中的技术纵深

    2024-03-22 07:30:01       17 阅读
  4. android11 系统的启动流程 的面试题目

    2024-03-22 07:30:01       18 阅读
  5. Python 机器学习 前向后向算法评估观察序列概率

    2024-03-22 07:30:01       18 阅读