JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<body>
<section id="skin">
<video id="myMovie" width="640" height="360">
<source src="http://zencoder-demo.s3.amazonaws.com/trailer_test.mp4"/>
</video>
<nav>
<div id="buttons">
<button type="button" id="playButton">Play</button>
</div>
<div id="defaultBar">
<div id="progressBar"></div>
</div>
<div style="clear:both"></div>
</nav>
</section>
<script>
function doFirst(){
barSize=600;
myMovie=document.getElementById('myMovie');
playButton=document.getElementById('playButton');
bar=document.getElementById('defaultBar');
progressBar=document.getElementById('progressBar');
playButton.addEventListener('click', playOrPause, false);
bar.addEventListener('click', clickedBar, false);
}
function playOrPause() {
if (!myMovie.paused && !myMovie.ended){
myMovie.pause();
playButton.innerHTML='Play';
window.clearInterval(updateBar);
} else {
myMovie.play();
playButton.innerHTML='Pause';
updateBar=setInterval(update, 500);
}
}
function update() {
if (!myMovie.ended) {
var size=parseInt(myMovie.currentTime*barSize/myMovie.duration);
progressBar.style.width=size+'px';
} else {
progressBar.style.width='0px';
playButton.innerHTML='Play';
window.clearInterval(updateBar);
}
}
function clickedBar(e){
if(!myMovie.paused && !myMovie.ended){
var mouseX=e.pageX-bar.offsetLeft;
var newtime=mouseX*myMovie.duration/barSize;
myMovie.currentTime=newtime;
progressBar.style.width=mouseX+'px';
}
}
window.addEventListener('load',doFirst,false);
</script>
</body>
CSS
body {
text-align: center;
}
header,section,footer,aside,nav,article,hgroup {
display: block;
}
#skin {
width:700px;
margin:10px auto;
padding:5px;
background:red;
border:4px solid black;
border-radius:10px;
}
nav {
margin: 5px 0px;
}
#buttons {
float:left;
width:70px;
height:22px;
}
#defaultBar {
position:relative;
float:left;
width:600px;
height:16px;
padding:4px;
border: 2px solid black;
background:yellow;
}
#progressBar {
position:absolute;
width:0px;
height:16px;
background:blue;
}