HTML5 Fullscreen API について読んでいました。今、ブラウザを全画面表示にするコードを見つけました。
ここで、フルスクリーンと通常のスクリーンを切り替える機能を追加したいと考えています。コードを完全に理解できません。
このボタンを使用すると、ブラウザーを全画面表示にできます。もう一度クリックすると通常に戻すことができるのはなぜですか?
CSS
<style>
body {
margin: 0px;
background-color: brown;
}
#contento:-webkit-full-screen {
width: 100%;
height: 100%;
}
#contento:-moz-full-screen {
width: 100%;
height: 100%;
}
</style>
Javascript
<script type="text/javascript">
function goFullscreen(id) {
// Get the element that we want to take into fullscreen mode
var element = document.getElementById(id);
// These function will not exist in the browsers that don't support fullscreen mode yet,
// so we'll have to check to see if they're available before calling them.
if (element.mozRequestFullScreen) {
// This is how to go into fullscren mode in Firefox
// Note the "moz" prefix, which is short for Mozilla.
element.mozRequestFullScreen();
} else if (element.webkitRequestFullScreen) {
// This is how to go into fullscreen mode in Chrome and Safari
// Both of those browsers are based on the Webkit project, hence the same prefix.
element.webkitRequestFullScreen();
}
// Hooray, now we're in fullscreen mode!
}
</script>
HTML
<body id="contento">
Hello
<button onclick="goFullscreen('contento'); return false">
Click Me To Go Fullscreen! (For real)
</button>