前端实现全屏功能

function openBig () {
  # 想要全屏展示的模块包含class名content 
  var elem = document.querySelector('.content');
  requestFullScreen(elem);
};

function requestFullScreen (elem) {
   #兼容不同的浏览器
  var requestMethod = elem.requestFullScreen || elem.webkitRequestFullScreen || elem.mozRequestFullScreen || elem.msRequestFullScreen;

  if (requestMethod) {
    requestMethod.call(elem)
  } else if (typeof window.ActiveXObject !== 'undefined') {
    #模拟F11 实现全屏
    var wscript = new ActiveXObject('WScript.Shell')

    if (wscript !== null) {
      wscript.SendKeys('{F11}')
    }
  }
}

你可能感兴趣的:(前端实现全屏功能)