HTML5的video雖然可用controls來展現控件,並進行控制播放暫停等,可是不一樣的瀏覽器顯示的效果可能不同,因此不少時候咱們須要使用Dom來進行自定義的一些操做和控制。下面是一個小例子。
固然效果不是很美觀,若想好看的能夠本身設置css樣式等。
javascript
<div id="video_div" style="text-align:center;">
<button onclick="playPause()">播放/暫停</button>
<button onclick="toBig()">大</button>
<button onclick="toNormal()">中</button>
<button onclick="toSmall()">小</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" />
您的瀏覽器不支持此HTML5 視頻標籤。
</video>
</div>
<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>
須要注意的是在全部屬性中,只有 videoWidth 和 videoHeight 屬性是當即可用的。
在視頻的元數據已加載後,其餘屬性纔可用。php