前面了解了 HTML5 中的 video 元素的使用,今天深入了解 video 元素 和 javascript 的拓展控制操作。直接上代码:
<div style="text-align:center;">
<button onclick="playPause()">播放/暂停</button>
<button onclick="makeBig()">大</button>
<button onclick="makeNormal()">中</button>
<button onclick="makeSmall()">小</button>
<br />
<video id="video1" width="200">
<source src="/movie.mp4" type="video/mp4" />
<source src="/movie.ogg" type="video/ogg" />
Your browser does not support HTML5 video.
</video>
</div>
<script type="text/javascript">
var myVideo=document.getElementById("video1");
function playPause()
{
if (myVideo.paused)
myVideo.play();
else
myVideo.pause();
}
function makeBig()
{
myVideo.width=500;
}
function makeSmall()
{
myVideo.width=300;
}
function makeNormal()
{
myVideo.width=400;
}
</script>
上面的示例使用了play() 和 pause() 两个方法。同时使用了两个属性:paused 和 width,下面我们来看看还有哪些方法、属性和事件:
方法 | 属性 | 事件 |
---|---|---|
play() | currentSrc | play |
pause() | currentTime | pause |
load() | videoWidth | progress |
canPlayType | videoHeight | error |
duration | timeupdate | |
ended | ended | |
error | abort | |
paused | empty | |
muted | emptied | |
seeking | waiting | |
volume | loadedmetadata | |
height | ||
width |
注:在所有属性中,只有 videoWidth 和 videoHeight 属性是立即可用的。在视频的元数据已加载后,其他属性才可用。
如果你发现错误或有其他见解,请给www.zhuei.com留言,我们会尽快更新本文!