javascript 控制页面全屏显示
2021/9/30 14:12:11
本文主要是介绍javascript 控制页面全屏显示,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
首先是按钮样式采用的是bootstrap样式
<!--全屏--> <a id="js_full_screen"> <i id="glyphicon" class="glyphicon glyphicon-fullscreen"></i> <span class="iconfont-full-screen"></span> </a>
下面是js代码
// 全屏 var $fullScreenEle = $('#js_full_screen'), $fsChildEle = $fullScreenEle.children(), $navbarEle = $('.zh-navbar'), $headerEle = $('.zh-header'), $glyphicon = $("#glyphicon"); $fullScreenEle.click(function() { if($fsChildEle.hasClass('iconfont-full-screen')) { // 全屏 var docEle = document.documentElement; var rfs = docEle.requestFullScreen || docEle.webkitRequestFullScreen || docEle.mozRequestFullScreen || docEle.msRequestFullScreen; if (rfs) { rfs.call(docEle); } else if (typeof window.ActiveXObject !== "undefined") { var wscript = new ActiveXObject("WScript.Shell"); if (wscript != null) { wscript.SendKeys("{F11}"); } } $fsChildEle.removeClass('iconfont-full-screen').addClass('iconfont-exit-screen'); $glyphicon.removeClass('glyphicon glyphicon-fullscreen').addClass('glyphicon glyphicon-move'); $navbarEle.hide(); $headerEle.css('top', 10); } else { // 退出全屏 var cfs = document.cancelFullScreen || document.webkitCancelFullScreen || document.mozCancelFullScreen || document.exitFullScreen; if (cfs) { cfs.call(document); } else if (typeof window.ActiveXObject !== "undefined") { var wscript = new ActiveXObject("WScript.Shell"); if (wscript != null) { wscript.SendKeys("{F11}"); } } } }); // 通过resize事件监听退出全屏 $(window).resize(function() { var prevWinHgt = window.sessionStorage.getItem('winHgt'); if(prevWinHgt) { if(window.innerHeight<prevWinHgt && $fsChildEle.hasClass('iconfont-exit-screen')) { $fsChildEle.removeClass('iconfont-exit-screen').addClass('iconfont-full-screen'); $glyphicon.removeClass('glyphicon glyphicon-move').addClass('glyphicon glyphicon-fullscreen'); $navbarEle.show(); $headerEle.css('top', 60); } } window.sessionStorage.setItem('winHgt', window.innerHeight); });
这篇关于javascript 控制页面全屏显示的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-02Java管理系统项目实战入门教程
- 2024-11-02Java监控系统项目实战教程
- 2024-11-02Java就业项目项目实战:从入门到初级工程师的必备技能
- 2024-11-02Java全端项目实战入门教程
- 2024-11-02Java全栈项目实战:从入门到初级应用
- 2024-11-02Java日志系统项目实战:初学者完全指南
- 2024-11-02Java微服务系统项目实战入门教程
- 2024-11-02Java微服务项目实战:新手入门指南
- 2024-11-02Java项目实战:新手入门教程
- 2024-11-02Java小程序项目实战:从入门到简单应用