I tried to use jQuery to control the HTML5 video. The two videos are in two tabs respectively. I want the video in the tab to be played immediately after the tab is clicked, in addition, the video in the tab can be stopped .,. I tried to use jQuery to control the HTML5 video. The two videos are in two tabs respectively. I want the video in the tab to be played immediately after the tab is clicked, and the video in the tab can be stopped.
My code is as follows:
$('#playMovie1').click(function(){$('#movie1').play();});
However, if this is not the case, you can use the following js:
document.getElementById('movie1').play();
Solution:
Play is not a jQuery function, but a function of DOM elements, so we need to call play through DOM. The Code is as follows:
$('#videoId').get(0).play();
The simplest method is Play and Pause:
$('video').trigger('play');$('video').trigger('pause');
Click a video to play and pause the video.
$("video").trigger("play");//for auto play$("video").addClass('pause');//for check pause or play add a class$('video').click(function() {if ($(this).hasClass('pause')) {$("video").trigger("play");$(this).removeClass('pause');$(this).addClass('play');} else {$("video").trigger("pause");$(this).removeClass('play');$(this).addClass('pause');}})
Mute and cancel mute
$('body').find("video").attr('id', 'video')var myVid = document.getElementById("video");$('.sound-icon').click(function() {//here "sound-icon" is a anchor class. var sta = myVid.muted;if (sta == true) {myVid.muted = false;} else {myVid.muted = true;}})
How to play a video in HTML 5:
Try this page in Safari 4! Or you can download the video instead.
Automatic playback:
Use poster to display images when videos cannot be loaded:
Try this page in Safari 4! Or you can download the video instead.
A concise example: