Skip to content

Instantly share code, notes, and snippets.

@simonewebdesign
Created August 8, 2013 09:48
Show Gist options
  • Save simonewebdesign/6183291 to your computer and use it in GitHub Desktop.
Save simonewebdesign/6183291 to your computer and use it in GitHub Desktop.
Full Screen in JavaScript (cross-browser) - another approach, with two different buttons
// quando clicco su enterfullscreen:
// vai in fullscreen
// mostra pulsante exitfullscreen
// nascondi header e footer
// quando clicco su exitfullscreen:
// esci da 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');
}
function doToggleFullScreen() {
toggleFullScreen();
toggleFullScreenButtons();
toggleHeaderFooter();
}
$('.enterfullscreen').on('click', function() {
doToggleFullScreen();
});
$('.exitfullscreen').on('click', function() {
doToggleFullScreen();
});
.enterfullscreen,
.exitfullscreen {
background-repeat: no-repeat;
}
.enterfullscreen {
background-image: url(/content/images/openfullscreen.png);
width:12px;
height: 12px;
position: absolute;
top:22px;
right:0;
}
.exitfullscreen {
background-image: url(/content/images/closefullscreen.png);
width: 27px;
height: 29px;
position: fixed;
top: 10px;
right: 10px;
z-index: 10;
display:none;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment