html+JS刷圖實現視頻效果,js視頻
網頁播放視頻需要載入播放器,但是通過刷圖也能實現視頻播放的效果
JS中用到Z-index屬性,記錄一篇講解Z-index屬性的部落格的地址:
http://www.cnblogs.com/gisdream/archive/2010/06/10/1755891.html
方法1:
JS的代碼
<script type="text/javascript">
var imageNr = 0;
var finished = new Array();
function createImageLayer() {
var img = new Image();
img.style.position = "absolute";
img.style.zIndex = 0;
img.onload = imageOnload;
img.width = 480;
img.height = 320;
img.src = "/?action=snapshot&n=" + (++imageNr);
var webcam = document.getElementById("webcam");
webcam.insertBefore(img, webcam.firstChild);
}
function imageOnload() {
this.style.zIndex = imageNr;
while (1 < finished.length) {
var del = finished.shift();
del.parentNode.removeChild(del);
}
finished.push(this);
createImageLayer();
}
</script>
html 的body
//網頁載入完成後開始調用createImageLayer()函數
<body onload="createImageLayer();" >
<div id="webcam" style="width:480px; height:320px;"></div>
方法一大概的工作原理就是Web前端向服務GET一張圖片,伺服器給Web前端
發一張圖片,迴圈擷取並顯示實現刷圖,現有大多數流浪器都支援此方法
方法2:
html 的body
<img src="/?action=snapshot" width="480px" height="320px" />
方法二不需要JS,簡單的使用html載入伺服器端的一張圖片即可,方法雖然簡單,但是大多數
瀏覽器不支援,暫時只發現Firefox(Mozilla Firefox)支援
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。