切换全屏

时间:2015-02-23 15:12:08

标签: javascript jquery html5 fullscreen

我想要一个简单的功能来切换全屏。这是我写的:

  function toggleFullScreen() {
    var elem = document.documentElement,
      request = elem.requestFullscreen || elem.msRequestFullscreen || elem.mozRequestFullScreen || elem.webkitRequestFullscreen,
      exit = document.exitFullscreen || document.msExitFullscreen || document.mozCancelFullScreen || document.webkitExitFullscreen;
    if (!document.fullscreenElement && !document.msFullscreenElement && !document.mozFullScreenElement && !document.webkitFullscreenElement) {
      request.call(elem);
    } else {
      exit.call(document);
    }
  }

任何更好或更简单的解决方案? 感谢。

0 个答案:

没有答案