2013-11-28 45 views
0

使用HTML 5視頻標記和jQuery,我成功獲得了以全屏模式打開的視頻,以響應事件(點擊,按鍵)。我如何讓視頻在頁面加載而不是onclick上以全屏方式打開?任何幫助,將不勝感激。非常感謝!獲取html 5視頻以全屏模式自動打開

我的HTML:

<div id="video_container> 
     <video id="video1" width="1280" height="720" controls autoplay> 
      <source src="videos/ballet.mp4" type="video/mp4"> 
      <source src="videos/ballet.webm" type="video/webm"> 
      <source src="videos/ballet.ogv" type="video/ogg"> 
     </video> 
    </div> 

我的javascript:

$(document).ready(function(){  
     $('#video1').bind("playing", function(){ 

     var elem = document.getElementById("video1"); 
     if (elem.requestFullscreen) { 
      elem.requestFullscreen(); 
     } else if (elem.mozRequestFullScreen) { 
      elem.mozRequestFullScreen(); 
     } else if (elem.webkitRequestFullscreen) { 
      elem.webkitRequestFullscreen(); 
     } 
     }); 

     $('#video1').bind("ended", function(){ 
     $("#video_container").hide(); 
     }); 
}); 
+0

http://css-tricks.com/custom-controls-in-html5-video-full-screen/ –

回答

4

聽起來像是你不能在頁面加載視頻全屏,至少不是WebKit瀏覽器。根據Safari開發庫:

的webkitEnterFullscreen()方法可僅響應於 被調用的用戶動作,例如點擊按鈕。例如,您無法調用 webkitEnterFullscreen()來響應加載事件。

全部文章在這裏:https://developer.apple.com/library/safari/documentation/audiovideo/conceptual/using_html5_audio_video/controllingmediawithjavascript/controllingmediawithjavascript.html