Answer the question
In order to leave comments, you need to log in
How to properly rewrite the script for multiple video elements?
There is a script that only works with one video and only one button attached to it.
The task is that when you click on the button, exactly that video is played and paused (A lot of videos can wash them and, accordingly, each has its own button). I am attaching a picture for clarity. Thank you for your reply
var overlay = document.getElementById('overlay');
var vid = document.getElementById('video');
if(overlay.addEventListener){
overlay.addEventListener("click", play, false)
}else if(overlay.attachEvent){
overlay.attachEvent("onclick", play)
}
function play() {
if (vid.paused){
vid.play();
overlay.className = "o";
}else {
vid.pause();
overlay.className = "";
}
}
Answer the question
In order to leave comments, you need to log in
Pause when another player starts playing. Same classes, different id.
$(".video-player").each(function (videoIndex) {
var videoId = $(this).attr("id");
video(videoId).ready(function() {
this.on("play", function(e) {
$(".video-player").each(function (index) {
if (videoIndex !== index) {
this.player.pause();
}
});
});
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question