html+JS刷圖實現視頻效果,js視頻

來源:互聯網
上載者:User

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)支援



著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.