isFullScreen.ts 1.42 KB
export const isFullScreen = (domName: any, htmlName: any) => {
  const isFullScreen = document.fullscreenElement
  const currentDatkTheme = htmlName.getAttribute('data-theme')

  if (isFullScreen) {
    console.log('退出全屏')
    if (document.exitFullscreen) {
      document.exitFullscreen()
      domName.style.background = ''
    } else if (document.msExitFullscreen) {
      document.msExitFullscreen()
      domName.style.background = ''
    } else if (document.mozCancelFullScreen) {
      document.mozCancelFullScreen()
      domName.style.background = ''
    } else if (document.webkitCancelFullScreen) {
      document.webkitCancelFullScreen()
      domName.style.background = ''
    }
  } else {
    console.log('进入全屏')
    if (domName.requestFullscreen) {
      domName.requestFullscreen()
      domName.style.background = currentDatkTheme === 'light' ? 'white' : '#18181c'
    } else if (domName.mozRequestFullScreen) {
      domName.mozRequestFullScreen()
      domName.style.background = currentDatkTheme === 'light' ? 'white' : '#18181c'
    } else if (domName.webkitRequestFullscreen) {
      domName.webkitRequestFullscreen()
      domName.style.background = currentDatkTheme === 'light' ? 'white' : '#18181c'
    } else if (domName.msRequestFullscreen) {
      domName.msRequestFullscreen()
      domName.style.background = currentDatkTheme === 'light' ? 'white' : '#18181c'
    }
  }
}