当前位置: 移动技术网 > IT编程>开发语言>JavaScript > JS实现全屏预览F11功能的示例代码

JS实现全屏预览F11功能的示例代码

2018年08月10日  | 移动技术网IT编程  | 我要评论

老是不通过,没办法,只能是重新发布了,反正我就是杠上了,大大小小写过很多前端特效,当然也经常在网上copy或者修改人家的代码,我觉得也挺好的,为什么?!因为我想这样,你能怎么办,打我?

少废话,直接上代码,

js代码

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?你问我,我问谁。好吧,我也很无赖。

举个小小例子,随便来一个按钮试试,按钮上在来个点击事件切换。

<html id="content">
  <body>
    <ul>
      <li>
        <a id="btnfullopen" href="javascript:void(0);" rel="external nofollow" rel="external nofollow" title="按“f11”进入全屏模式">
          <i class="ace-icon fa fa-arrows-alt"></i>全屏查看
        </a>
        <a id="btnfullquite" href="javascript:void(0);" rel="external nofollow" rel="external nofollow" 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调用代码

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");
};

只做个人备忘,不做任何发表,不做信息交流。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网