video 全屏,播放,隱藏控件。

requestFullscreen全屏具體實現

1.進入全屏
function full(ele) { if (ele.requestFullscreen) { ele.requestFullscreen(); } else if (ele.mozRequestFullScreen) { ele.mozRequestFullScreen(); } else if (ele.webkitRequestFullscreen) { ele.webkitRequestFullscreen(); } else if (ele.msRequestFullscreen) { ele.msRequestFullscreen(); } } 

ele:要全屏的元素,能夠是document.body也能夠是某一個div
思路:
1.判斷該瀏覽器是否具備requestFullscreen方法
2.有,則直接執行ele.requestFullscreen();沒有則作瀏覽器兼容判斷。javascript

2.exitFullScreen退出全屏
function exitFullscreen() { if(document.exitFullScreen) { document.exitFullScreen(); } else if(document.mozCancelFullScreen) { document.mozCancelFullScreen(); } else if(document.webkitExitFullscreen) { document.webkitExitFullscreen(); } else if(document.msExitFullscreen) { document.msExitFullscreen(); } } 

退出全屏直接使用document調用exitFullscreen方法便可。css

3.獲取當前全屏的節點
function getFullscreenElement() { return ( document.fullscreenElement || document.mozFullScreenElement || document.msFullScreenElement || document.webkitFullscreenElement||null ); } 

document.fullscreenElement():獲取當前全屏的元素。
假設id爲div1的Element當前爲全屏狀態則 document.querySelector("#div1")===document.fullscreenElementjava

4.判斷當前是否全屏
function isFullScreen() { return !! ( document.fullscreen || document.mozFullScreen || document.webkitIsFullScreen || document.webkitFullScreen || document.msFullScreen ); } 
5.判斷當前文檔是否能切換到全屏
function isFullscreenEnabled() { return ( document.fullscreenEnabled || document.mozFullScreenEnabled || document.webkitFullscreenEnabled || document.msFullscreenEnabled ); } 

注意事項:

1.document下沒有requestFullscreen
2.requestFullscreen方法只能由用戶觸發,好比:在onload事件中不能觸發
3.頁面跳轉需先退出全屏
4.進入全屏的元素,將脫離其父元素,因此可能致使以前某些css的失效
解決方案:使用 :full-screen僞類 爲元素添加全屏時的樣式(使用時爲了兼容注意添加-webkit、-moz或-ms前綴)
5.一個元素A全屏後,其子元素要再全屏,需先讓元素A退出全屏web


 單擊播放/暫停。瀏覽器

function onDocumentClick(event) {
clearTimeout(clickTimeId);
//執行延時
clickTimeId = setTimeout(function() {
//此處爲單擊事件要執行的代碼
if(video.paused){
video.play();
}else{
video.pause();
}
}, 250);
}
雙擊全屏/解除全屏
function onDocumenDblClick(event) {
clearTimeout(clickTimeId);
console.log("鼠標雙擊");
console.log(isFullScreen())
if(isFullScreen()){
exitFullscreen()
}else{
full(video)
}

}


隱藏vedio控件 css :
video::-webkit-media-controls{    display:none !important;}
相關文章
相關標籤/搜索