TAG
CSS
JavaScript
Result
Run
License
<button type="button" class="btn">View to Fullscreen</button> <p class="target"> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. <button type="button" id="btn-exit" class="btn-fullscreen-exit">Exit fullscreen</button> </p>
.btn-fullscreen-exit { display: none; } p:fullscreen { background: #CCC; font-size: 2em; } p:fullscreen .btn-fullscreen-exit { display: block; font-size: inherit; }
window.addEventListener("load", function() { document.querySelector(".btn").onclick = function() { const elReqFullScreen = this.nextElementSibling; elReqFullScreen.requestFullscreen(); // fullscreen을 시작(또는 종료)할 시점을 이벤트로 확인 document.addEventListener("fullscreenchange", () => { const elFullscreen = document.fullscreenElement; // elFullscreen이 null이 아니면 fullscreen 상태 if(elFullscreen) { let elBtnExit = elFullscreen.querySelector(".btn-fullscreen-exit"); elBtnExit.onclick = () => document.exitFullscreen(); } else { console.log("exit fullscreen"); } }); }; });
Console
expand_less
License
License
by DevDic
Close