下面小編就為大家帶來一篇元素全螢幕的設定與監聽實例,具有很好的參考價值,希望對大家有幫助。一起跟著小編過來看看吧
設定全螢幕和退出全螢幕
//全屏设置 $('#fullScreen').on('click', function () { fullScreen(); }); //退出全屏 $('#exitFullScreen').on('click', function () { exitFullScreen(); }); //进入全屏 function fullScreen() { var obj = document.getElementById('editMark'); if (obj.requestFullScreen) { obj.requestFullScreen(); } else if (obj.webkitRequestFullScreen) { obj.webkitRequestFullScreen(); } else if (obj.msRequestFullScreen) { obj.msRequestFullScreen(); } else if (obj.mozRequestFullScreen) { obj.mozRequestFullScreen(); } } function exitFullScreen() { var obj = document.getElementById('editMark'); if (document.exitFullscree) { document.exitFullscree(); } else if (document.webkitExitFullscreen) { document.webkitExitFullscreen(); } else if (document.msExitFullscreen) { document.msExitFullscreen(); } else if (document.mozCancelFullScreen) { document.mozCancelFullScreen(); } }
監聽全螢幕事件
//监听全屏 document.addEventListener('fullscreenchange', function () { if (document.fullscreenElement) { alert(1); } else { alert(2); } }, false); document.addEventListener('msfullscreenchange', function () { if (document.msFullscreenElement) { alert(1); } else { alert(2); } }, false); document.addEventListener('mozfullscreenchange', function () { if (document.mozFullScreen) { alert(1); } else { alert(2); } }, false); document.addEventListener('webkitfullscreenchange', function () { if (document.webkitIsFullScreen) { alert(1); } else { alert(2); } }, false);
上面是我整理給大家的,希望今後對大家有幫助。
相關文章:
以上是使用元素全螢幕如何做到設定與監聽的詳細內容。更多資訊請關注PHP中文網其他相關文章!