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(); // 开始循环播放
相关推荐
demi_meng3 小时前
reactNative 遇到的问题记录
javascript·react native·react.js
千码君20164 小时前
React Native:从react的解构看编程众多语言中的解构
java·javascript·python·react native·react.js·解包·解构
EndingCoder6 小时前
WebSocket实时通信:Socket.io
服务器·javascript·网络·websocket·网络协议·node.js
我胡为喜呀6 小时前
Vue3 中的 watch 和 watchEffect:如何优雅地监听数据变化
前端·javascript·vue.js
liangshanbo12159 小时前
React 19 vs React 18全面对比
前端·javascript·react.js
Never_Satisfied9 小时前
在 JavaScript 中,删除数组中内容为xxx的元素
java·前端·javascript
_菜鸟果果9 小时前
Vue3+echarts 3d饼图
前端·javascript·echarts
rechol10 小时前
类与对象(中)笔记整理
java·javascript·笔记
Luffe船长10 小时前
前端vue2+js+springboot实现excle导入优化
前端·javascript·spring boot
Demoncode_y10 小时前
前端布局入门:flex、grid 及其他常用布局
前端·css·布局·flex·grid