-
-
Save gmmorris/8861160 to your computer and use it in GitHub Desktop.
Small snippet for a fullscreen mode utility
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
<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> |
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
(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