HTML5 sample code for custom control using DOM

Source: Internet
Author: User

Comments: Although HTML 5 video can be used to display controls and pause playback, different browsers may display different effects, we will share with you the following information about using Dom to perform custom operations and control HTML5 video. Although controls can be used to display controls and control playing pause, however, different browsers may display different effects, so we often need to use Dom for custom operations and control. The following is a small example.
Of course, the effect is not very beautiful. If you want to have a good view, you can set your own css style.

The Code is as follows:
<Div id = "video_div" style = "text-align: center;">
<Button onclick = "playPause ()"> play/pause </button>
<Button onclick = "toBig ()"> large </button>
<Button onclick = "toNormal ()"> medium </button>
<Button onclick = "toSmall ()"> small </button>

<Video id = "myVideo" width = "500" height = "250" style = "margin-top: 15px;">
<Source src = "demo.mp4" type = "video/mp4"/>
<Source src = "demo.ogg" type = "video/ogg"/>
Your browser does not support this HTML5 video tag.
</Video>
</Div>


The Code is as follows:
<Script type = "text/javascript">
Var myVideo = document. getElementById ("myVideo ");
Function playPause ()
{
If (myVideo. paused)
MyVideo. play ();
Else
MyVideo. pause ();
}
Function toBig ()
{
MyVideo. width = 560;
}
Function toNormal ()
{
MyVideo. width = 420;
}
Function toSmall ()
{
MyVideo. width = 320;
}
</Script>

Note that only the videoWidth and videoHeight attributes are available immediately in all attributes.
Other attributes are available only after the video metadata has been loaded.

Related Article

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.