Skip to content

Instantly share code, notes, and snippets.

@gmmorris
Forked from webapprentice/tutorial_39_example_1.html
Last active August 29, 2015 13:56
Show Gist options
  • Save gmmorris/8861160 to your computer and use it in GitHub Desktop.
Save gmmorris/8861160 to your computer and use it in GitHub Desktop.
Small snippet for a fullscreen mode utility
<div id='container'>
<img src='assets/slideshow_3.png' id='myimage' />
</div>
<p style='text-align: center'>
Click the image to expand - Hit the ESC key to collapse
</p>
<style type="text/css">
#myimage {
height: 300px;
display:block;
margin: auto;
}
:-webkit-full-screen #container {
width: 100%;
height: 100%;
}
:-webkit-full-screen #myimage {
height: 600px;
}
:-moz-full-screen #container {
width: 100%;
height: 100%;
}
:-moz-full-screen #myimage {
height: 600px;
}
</style>
<script>
var container = document.getElementById("container");
var myimage = document.getElementById("myimage");
myimage.addEventListener("click", function(e) {
uiFullScreenUtil(container);
}, false);
</script>
(function (window, document, undefined) {
/***
* Internal functions to provide us with one cross-browser call for requestFullscreen and exitFullscreen
*/
var requestFullscreen = function (element) {
if (element.requestFullscreen) {
element.requestFullscreen();
} else if (element.mozRequestFullScreen) { // note the upper case S
element.mozRequestFullScreen();
} else if (element.webkitRequestFullscreen) {
element.webkitRequestFullscreen();
} else if (element.msRequestFullscreen) {
element.msRequestFullscreen();
}
};
var exitFullscreen = (function () {
return (document.exitFullscreen || document.webkitExitFullscreen || document.mozExitFullScreen || document.msExitFullscreen);
})();
document.exitFullscreen = exitFullscreen;
window.uiFullScreenUtil = function (elm) {
if (elm && !document.fullscreenElement) {
requestFullscreen(elm);
} else if (document.fullscreenElement) {
exitFullscreen();
}
};
})(window, document)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment