Skip to content

Instantly share code, notes, and snippets.

@wesley6j
Forked from simonewebdesign/fullscreen3.js
Created August 16, 2017 19:21
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 wesley6j/3503ede73fa198d9321cfb087976f6ec to your computer and use it in GitHub Desktop.
Save wesley6j/3503ede73fa198d9321cfb087976f6ec to your computer and use it in GitHub Desktop.
JavaScript Full Screen API (completely cross-browser!)
// quando clicco su enterfullscreen:
// vai in fullscreen
// all'entrata in fullscreen:
// mostra pulsante exitfullscreen
// nascondi header e footer
// quando clicco su exitfullscreen:
// esci da fullscreen
// all'uscita dal fullscreen:
// mostra pulsante enterfullscreen
// mostra header e footer
function toggleFullScreen() {
if (!document.fullscreenElement && // alternative standard method
!document.mozFullScreenElement && !document.webkitFullscreenElement) { // current working methods
if (document.documentElement.requestFullscreen) {
document.documentElement.requestFullscreen();
} else if (document.documentElement.mozRequestFullScreen) {
document.documentElement.mozRequestFullScreen();
} else if (document.documentElement.webkitRequestFullscreen) {
document.documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
}
} else {
if (document.cancelFullScreen) {
document.cancelFullScreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitCancelFullScreen) {
document.webkitCancelFullScreen();
}
}
}
function toggleFullScreenButtons() {
$(_objects.enterfullscreen).toggle();
$(_objects.exitfullscreen).toggle();
}
function toggleHeaderFooter() {
$('#header').slideToggle('slow');
$('#footer').slideToggle('slow');
}
$(_objects.enterfullscreen).on('click', function () {
toggleFullScreen();
});
$(_objects.exitfullscreen).on('click', function () {
toggleFullScreen();
});
// event listeners
document.addEventListener("fullscreenchange", function () {
toggleFullScreenButtons();
toggleHeaderFooter();
}, false);
document.addEventListener("mozfullscreenchange", function () {
toggleFullScreenButtons();
toggleHeaderFooter();
}, false);
document.addEventListener("webkitfullscreenchange", function () {
toggleFullScreenButtons();
toggleHeaderFooter();
}, false);
if (!Modernizr.fullscreen) // fallback for browsers who doesn't support the Full Screen API
{
$(_objects.enterfullscreen).on('click', function() {
toggleFullScreenButtons();
toggleHeaderFooter();
});
$(_objects.exitfullscreen).on('click', function() {
toggleFullScreenButtons();
toggleHeaderFooter();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment