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

1.html代码

java 复制代码
<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代码

java 复制代码
video {
		     object-fit: fill;  
		}
  1. js代码
java 复制代码
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(); // 开始循环播放
相关推荐
摘星编程10 小时前
React Native for OpenHarmony 实战:Linking 链接处理详解
javascript·react native·react.js
胖者是谁10 小时前
EasyPlayerPro的使用方法
前端·javascript·css
EndingCoder10 小时前
索引类型和 keyof 操作符
linux·运维·前端·javascript·ubuntu·typescript
摘星编程11 小时前
React Native for OpenHarmony 实战:ImageBackground 背景图片详解
javascript·react native·react.js
摘星编程12 小时前
React Native for OpenHarmony 实战:Alert 警告提示详解
javascript·react native·react.js
Joe55612 小时前
vue2 + antDesign 下拉框限制只能选择2个
服务器·前端·javascript
WHS-_-202212 小时前
Tx and Rx IQ Imbalance Compensation for JCAS in 5G NR
javascript·算法·5g
摘星编程12 小时前
React Native for OpenHarmony 实战:GestureResponderSystem 手势系统详解
javascript·react native·react.js
lili-felicity12 小时前
React Native for OpenHarmony 实战:加载效果的实现详解
javascript·react native·react.js·harmonyos
济61713 小时前
linux 系统移植(第六期)--Uboot移植(5)--bootcmd 和 bootargs 环境变量-- Ubuntu20.04
java·前端·javascript