jsを使用して複数のビデオを実現し、1つの再生を他の一時停止
9433 ワード
html
js
<div class="videoContent">
<div class="videoMod">
<h3> : , !h3>
<video src="./video/video1.mp4" controls > video 。video>
div>
<div class="videoMod">
<h3> : , !h3>
<video src="./video/video2.mp4" controls > video 。video>
div>
<div class="videoMod">
<h3> :“ ” , !h3>
<video src="./video/video3.mp4" controls > video 。video>
div>
div>
js
window.onload=function(){
var videos = document.getElementsByTagName('video');// video
// video video pauseAll video
for (var i = videos.length - 1; i >= 0; i--) {
(function(n){
videos[n].addEventListener('play',function(){
pauseAll(n);
})
})(i)
}
// video
function pauseAll(index){
for (var j = videos.length - 1; j >= 0; j--) {
if (j!=index){
videos[j].pause();
videos[j].load();
}
}
};
}