Use jQuery to control HTML5 video playback/pause-

Source: Internet
Author: User
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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.