码迷,mamicode.com
首页 > Web开发 > 详细

js 全屏代码实现方法

时间:2019-10-07 19:44:42      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:cal   click   script   efs   ict   ram   call   amp   html   

 1 /* 全屏方法
 2  * =========
 3     <button class="roll-nav roll-right fullscreen">
 4         <i class="fa fa-arrows-alt"></i>
 5     </button>
 6 */
 7 +function ($) {
 8     ‘use strict‘;
 9 
10     /* 
11     * [setFullscreen 设置全屏] 
12     * @param {domElement} element [DOM节点对象(可选)] 
13     */
14     var setFullscreen = function (element) {
15         var el = element instanceof HTMLElement ? element : document.documentElement;
16         var rfs = el.requestFullscreen || el.webkitRequestFullscreen || el.mozRequestFullScreen || el.msRequestFullscreen;
17         if (rfs) {
18             rfs.call(el);
19         } else if (window.ActiveXObject) {
20             var ws = new ActiveXObject("WScript.Shell");
21             ws && ws.SendKeys("{F11}");
22         }
23     }
24     /*
25     * [exitFullscreen 退出全屏] 
26     */
27     var exitFullscreen = function () {
28         var efs = document.exitFullscreen || document.webkitExitFullscreen || document.mozCancelFullScreen || document.msExitFullscreen;
29         if (efs) {
30             efs.call(document);
31         } else if (window.ActiveXObject) {
32             var ws = new ActiveXObject("WScript.Shell");
33             ws && ws.SendKeys("{F11}");
34         }
35     }
36 
37     var isFullScreen = false;
38     var handleFullScreen = function () {
39         if (isFullScreen) {
40             exitFullscreen();
41             isFullScreen = false;
42         } else {
43             setFullscreen();
44             isFullScreen = true;
45         }
46     }
47 
48     $("button.fullscreen").on(‘click‘, function (event) {
49         handleFullScreen();
50     });
51 }(jQuery);

 

js 全屏代码实现方法

标签:cal   click   script   efs   ict   ram   call   amp   html   

原文地址:https://www.cnblogs.com/wsk198726/p/11631488.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!