-
-
Save vinnycrazzy/26c79237247c6b3a46574e0a75060dbc to your computer and use it in GitHub Desktop.
A simple function to toggle fullscreen in JavaScript. It work well on Firefox and Webkit browsers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Toggle fullscreen function who work with webkit and firefox. | |
* @function toggleFullscreen | |
* @param {Object} event | |
*/ | |
function toggleFullscreen(event) { | |
var element = document.body; | |
if (event instanceof HTMLElement) { | |
element = event; | |
} | |
var isFullscreen = document.webkitIsFullScreen || document.mozFullScreen || false; | |
element.requestFullScreen = element.requestFullScreen || element.webkitRequestFullScreen || element.mozRequestFullScreen || function () { return false; }; | |
document.cancelFullScreen = document.cancelFullScreen || document.webkitCancelFullScreen || document.mozCancelFullScreen || function () { return false; }; | |
isFullscreen ? document.cancelFullScreen() : element.requestFullScreen(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment