Skip to content

Instantly share code, notes, and snippets.

@MAKIO135
Created March 27, 2019 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MAKIO135/68291e6543a452f28c263a3d40f108f1 to your computer and use it in GitHub Desktop.
Save MAKIO135/68291e6543a452f28c263a3d40f108f1 to your computer and use it in GitHub Desktop.
utilities for toggling fullscreen
// https://stackoverflow.com/a/23971798
window.addEventListener('click', () => {
toggleFullScreen()
})
function isFullScreen() {
return (document.fullScreenElement && document.fullScreenElement !== null)
|| document.mozFullScreen
|| document.webkitIsFullScreen
}
function requestFullScreen(element) {
if (element.requestFullscreen)
element.requestFullscreen()
else if (element.msRequestFullscreen)
element.msRequestFullscreen()
else if (element.mozRequestFullScreen)
element.mozRequestFullScreen()
else if (element.webkitRequestFullscreen)
element.webkitRequestFullscreen()
}
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()
}
function toggleFullScreen(element) {
if (isFullScreen()) exitFullScreen()
else requestFullScreen(element || document.documentElement)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment