Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement Custom player with html5

Shulou Source: shulou.com Published: 2022-06-01 07:26:58 09月30日 Update

This article mainly shows you "html5 how to achieve a custom player", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "html5 how to achieve a custom player" this article.

The code is as follows:

Play

Css style

Body {text-align:center;} header, section, footer, side, navigation, article, hgroup {display:block;} # skin {width:700px;margin:10px automatic; inner margin: 5px; background: red; border: 4px pure black; border-radius:20px;} nav {margin:5px0px;} # buttons {float:left; width: 70px; height: 22px;} # defaultBar {position:relative; floats to the left; width: 600px; height: 14 pixels Inner margin: 4px; frame: 1px pure black; background: yellow;} / * progressBar inside defaultBar * / # progressBar {position: absolute; width: 0px * javascript control change * / height:14px;/* and defaultBar height same * / background:blue;}

Javascript code

The function doFisrt () {barSize=600;// is careful not to use px units and do not use var, which is a variable variable myMovie=document.getElementById ('myMovie'); playButton=document.getElementById (' playButton'); bar=document.getElementById ('defaultBar'); progressBar=document.getElementById (' progressBar'); playButton.addEventListener ('click',playOrPause,false); / / the third argument is always false, registering the event handler for the bubbling phase. Bar.addEventListener ('click',clickedBar,false);} / / controls the movie playback and stop function playOrPause () {if (! MyMovie.pausedbread! MyMovie.ended) {myMovie.pause (); playButton [XSS _ clean] = 'play'; window.clearInterval (updatedBar); playButton [XSS _ clean] = 'pause'; UpdatedBar=setInterval (update 500);}} / / controls the dynamic display function of the progress bar update () {if (! MyMovie.ended) {varsize=parseInt (myMovie.currentTime*barSize/myMovie.duration); progressBar.style.width=size+'px';} else {progressBar.style.width='0px'; playButton [XSS _ clean] = 'play'; window.clearInterval (updatedBar);}} / / Click the progress bar control method function clickedBar (e) {if (! MyMovie.pausedbread! MyMovie.ended) {varmouseX=e.pageX-bar.offsetLeft;varnewtime=mouseX*myMovie.duration/barSize;// new start time myMovie.currentTime=newtime;progressBar.style.width=mouseX+' window.clearInterval (updatedBar);}} window.addEventListener ('load', doFisrt,FALSE). This is all the content of the article "how to implement a custom player in html5". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Control player content width article height code function function variable background border progress black learning help same three event location Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Shulou Technology Redmi MariaDB Apple