jsフルスクリーンイベントfullscreenchangeは、フルスクリーンに入り、フルスクリーン操作を終了します.

6644 ワード

1.
function launchFullscreen(element) {
  if (element.requestFullscreen) {
    element.requestFullscreen()
  } else if (element.mozRequestFullScreen) {
    element.mozRequestFullScreen()
  } else if (element.msRequestFullscreen) {
    element.msRequestFullscreen()
  } else if (element.webkitRequestFullscreen) {
    element.webkitRequestFullScreen()
  }
}

launchFullscreen(document.documentElement) //         
launchFullscreen(document.getElementById("id")) //        
2.
function exitFullscreen() {
  if (document.exitFullscreen) {
    document.exitFullscreen()
  } else if (document.msExitFullscreen) {
    document.msExitFullscreen()
  } else if (document.mozCancelFullScreen) {
    document.mozCancelFullScreen()
  } else if (document.webkitExitFullscreen) {
    document.webkitExitFullscreen()
  }
}
exitFullscreen()

3.
document.addEventListener("fullscreenchange", function (e) {
  if (document.fullscreenElement) {
    console.log('    ')
  } else {
    console.log('    ')
  }
})