替代Flash技术最好的选择------HTML5(2)
- UID
- 1066743
|
替代Flash技术最好的选择------HTML5(2)
3、代码示例
<body>
<video controls poster="gg.jpg" width="300px" height="400px" style="background:black" preload="auto">
您的浏览器不支持播放该格式视频
<source src="video.mp4">
<source src="video.ogg">
<source src="video.webm">
</video>
<button id="btn"></button>
</body>
<script>
var btn = document.getElementById('btn');
btn.onclick = function(){
var video = document.getElementsByTagName('video')[0];
//paused当前视频是否暂停,暂停返回true
if (video.paused) {
video.play();
btn.innerHTML = "暂停";
}else{
video.pause();
btn.innerHTML = "播放";
}
video.onplay = function(){
console.log("====");
}
video.onended = function(){
console.log("++++");
}
}
</script>
4、运行结果
Paste_Image.png |
|
|
|
|
|