js设置页面全屏
程序员文章站
2022-08-17 16:42:36
html代码 js代码 ......
html代码
<!-- 全屏按钮 --> <img id="alarm-fullscreen-toggler" src="/public/index/images/open.png" alt="全屏按钮" />
js代码
// 设置全屏 $('#alarm-fullscreen-toggler').on('click', function (e) { var element = document.documentelement; // 返回 html dom 中的root 节点 <html> if(!$('body').hasclass('full-screen')) { $('body').addclass('full-screen'); $('#alarm-fullscreen-toggler').addclass('active'); // 判断浏览器设备类型 if(element.requestfullscreen) { element.requestfullscreen(); } else if (element.mozrequestfullscreen){ // 兼容火狐 element.mozrequestfullscreen(); } else if(element.webkitrequestfullscreen) { // 兼容谷歌 element.webkitrequestfullscreen(); } else if (element.msrequestfullscreen) { // 兼容ie element.msrequestfullscreen(); } // 切换全屏按钮 $('#alarm-fullscreen-toggler').attr('src','/public/index/images/close.png'); } else { // 退出全屏 console.log(document); $('body').removeclass('full-screen'); $('#alarm-fullscreen-toggler').removeclass('active'); // 退出全屏 if(document.exitfullscreen) { document.exitfullscreen(); } else if (document.mozcancelfullscreen) { document.mozcancelfullscreen(); } else if (document.webkitcancelfullscreen) { document.webkitcancelfullscreen(); } else if (document.msexitfullscreen) { document.msexitfullscreen(); } // 切换全屏按钮 $('#alarm-fullscreen-toggler').attr('src','/public/index/images/open.png'); } });
上一篇: 设计模式实战研磨 ——UML环境搭建