Skip to content

Instantly share code, notes, and snippets.

@xsephiroth
Created December 7, 2018 06:40
Show Gist options
  • Save xsephiroth/644ac08b66c3aef73e0acaaee0f0a746 to your computer and use it in GitHub Desktop.
Save xsephiroth/644ac08b66c3aef73e0acaaee0f0a746 to your computer and use it in GitHub Desktop.
html5 fullscreen
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style link="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css"></style>
<style>
body {
margin: 0;
padding: 0;
position: relative;
height: 100vh;
background-color: skyblue;
}
.ctrl {
height: 100px;
width: 100%;
border: 1px solid blue;
position: absolute;
box-sizing: border-box;
bottom: 0;
}
</style>
</head>
<body>
<button onclick="toggleFullScreen()">toggle</button>
<div class="ctrl"></div>
<div class="ctrl"></div>
<div class="ctrl"></div>
<div class="ctrl"></div>
<div class="ctrl"></div>
<script>
function toggleFullScreen() {
var doc = window.document;
var docEl = doc.documentElement;
var requestFullScreen = docEl.requestFullscreen || docEl.mozRequestFullScreen || docEl.webkitRequestFullScreen || docEl.msRequestFullscreen;
var cancelFullScreen = doc.exitFullscreen || doc.mozCancelFullScreen || doc.webkitExitFullscreen || doc.msExitFullscreen;
if (!doc.fullscreenElement && !doc.mozFullScreenElement && !doc.webkitFullscreenElement && !doc.msFullscreenElement) {
requestFullScreen.call(docEl);
}
else {
cancelFullScreen.call(doc);
}
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment