Skip to content

Instantly share code, notes, and snippets.

@ruempel
Created February 25, 2019 15:24
Show Gist options
  • Save ruempel/2790a623b8bc0d1a69a5556a01211cbd to your computer and use it in GitHub Desktop.
Save ruempel/2790a623b8bc0d1a69a5556a01211cbd to your computer and use it in GitHub Desktop.
Demonstrate JavaScript fullscreen API
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Fullscreen Demo</title>
<style>
html {
font-size: 20px;
}
section {
background-color: #bda;
padding: 3rem;
margin: 1rem;
}
</style>
<script>
function activateFullscreen() {
let elem = document.getElementById("second");
if (elem.requestFullscreen) {
elem.requestFullscreen();
}
}
window.onload = function () {
document.getElementById("switch").addEventListener("click", activateFullscreen);
};
</script>
</head>
<body>
<section>First Section</section>
<section id="second">
<p>Second Section</p>
<button id="switch">Activate Fullscreen (Come back with ESCAPE key)</button>
</section>
<section>Third Section</section>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment