I have a video gallery, each item looks like
<video muted="" allowfullscreen="" autoplay="" controls="" controlslist="nodownload noplaybackrate" disablepictureinpicture="" class="story loop="" poster="" style="max-height: 500px; width: 349px;" id="">
<source src="https://example.com/video.mp4" type="video/mp4">
</video>
They have to look like gifs - on autoplay, and if user switches on the sound on one of the video, the others have to became muted, because now it's possible to switch on the sound on more then one video, and it's too much sound. I tried already that ways, and they didn't help 1
jQuery('video').on('volumechange', function() {
jQuery('video').attr('muted');
jQuery(this).removeAttr('muted');
})
2
jQuery('video').on('volumechange', function() {
jQuery('video').prop('muted', true);
jQuery(this).prop('muted', false);
})
3 - with the Class
jQuery('video').on('volumechange', function() { jQuery('video').removeClass('sound'); jQuery(this).addClass('sound'); jQuery('video').attr('muted'); jQuery('video.sound').removeAttr('muted');
})
and 4 - the native js after clothing jquery tag
const videoElements = document.getElementsByTagName('video');
for (const currentVideoElement of videoElements) {
currentVideoElement.addEventListener('volumechange', () => {
for (const otherVideoElement of videoElements) {
if (otherVideoElement !== currentVideoElement) {
otherVideoElement.muted = true;
}
}
});
}
What else could help, where I'm wrong? Would be very good if no extra libraries needed.
Via Active questions tagged javascript - Stack Overflow https://ift.tt/hUu0LYs
Comments
Post a Comment