JS 實現全屏預覽 F11功能

總是不經過,沒辦法,只能是從新發布了,反正我就是槓上了,大大小小寫過不少前端特效,固然也常常在網上copy或者修改人家的代碼,我以爲也挺好的,爲何?!由於我想這樣,你能怎麼辦,打我?
少廢話,直接上代碼,
JS代碼javascript

function fullScreen(el) {
    var rfs = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullScreen,
        wscript;
 
    if(typeof rfs != "undefined" && rfs) {
        rfs.call(el);
        return;
    }
 
    if(typeof window.ActiveXObject != "undefined") {
        wscript = new ActiveXObject("WScript.Shell");
        if(wscript) {
            wscript.SendKeys("{F11}");
        }
    }
}
 
function exitFullScreen(el) {
    var el= document,
        cfs = el.cancelFullScreen || el.webkitCancelFullScreen || el.mozCancelFullScreen || el.exitFullScreen,
        wscript;
 
    if (typeof cfs != "undefined" && cfs) {
      cfs.call(el);
      return;
    }
 
    if (typeof window.ActiveXObject != "undefined") {
        wscript = new ActiveXObject("WScript.Shell");
        if (wscript != null) {
            wscript.SendKeys("{F11}");
        }
  }
}

HTML代碼
最近受了一點點小刺激,對本身作的工做產生迷茫,不知道還要作這個作多久,還有我其實仍是喜歡設計多一些,還有我喜歡設計,可是設計太難了,常常以爲本身作的東西跟別人的,比起來差個好幾萬塊錢,Why?你問我,我問誰。好吧,我也很無賴。
舉個小小例子,隨便來一個按鈕試試,按鈕上在來個點擊事件切換。php

<html id="Content">
    <body>
        <ul>
            <li>
                <a id="BtnFullOpen" href="javascript:void(0);" title="按「F11」進入全屏模式">
                    <i class="ace-icon fa fa-arrows-alt"></i>全屏查看
                </a>
                <a id="BtnFullQuite" href="javascript:void(0);" title="按「F11」關閉全屏模式" style="display:none;">
                    <i class="ace-icon fa fa-arrows-alt"></i>全屏關閉
                </a>
            </li>
            <li>2</li>
            <li>3</li>
            <li>5</li>
        </ul>
    </body>
</html>

記得必定要加上調用代碼,調用代碼,調用代碼,說三遍...
JS調用代碼html

var oBtnFullOpen = document.getElementById('BtnFullOpen');
var oContent = document.getElementById('Content');
oBtnFullOpen.onclick = function() {
    fullScreen(oContent);
    oBtnFullQuite.setAttribute("style", "display:block");
    oBtnFullOpen.setAttribute("style", "display:none");
}
var oBtnFullQuite = document.getElementById('BtnFullQuite');
oBtnFullQuite.onclick = function() {
    exitFullScreen(oContent);
    oBtnFullQuite.setAttribute("style", "display:none");
    oBtnFullOpen.setAttribute("style", "display:block");
};

只作我的備忘,不作任何發表,不作信息交流。
儘管拿去用,不謝!
原文地址:https://segmentfault.com/a/11...
轉載於猿2048:➱《JS 實現全屏預覽 F11功能》前端

相關文章
相關標籤/搜索