이번 시간에는 비디오 전체화면 기능을 추가해보겠습니다.
youtube
|views
|mixins
*|videoPlayer.pug
|assets
|js
*|videoPlayer.js
.videoPlayer#jsVideoContainer
video(src=video.src)
.videoPlayer__controls
.videoPlayer__column
/*생략*/
.videoPlayer__column
span.expand#jsFullscreen
i.fas.fa-expand
const videoContainer = document.querySelector('#jsVideoContainer');
const fullscreen = document.querySelector('#jsFullscreen');
function goFullscreen(){
if (videoContainer.requestFullscreen) {
videoContainer.requestFullscreen();
} else if (videoContainer.mozRequestFullScreen) {
videoContainer.mozRequestFullScreen();
} else if (videoContainer.webkitRequestFullscreen) {
videoContainer.webkitRequestFullscreen();
} else if (videoContainer.msRequestFullscreen) {
videoContainer.msRequestFullscreen();
}
fullScreen.innerHTML = '<i class="fas fa-compress"></i>';
fullscreen.removeEventListener('click', goFullscreen);
fullscreen.addEventListener('click', exitFullscreen);
}
function exitFullscreen(){
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
fullscreen.innerHTML = '<i class="fas fa-expand"></i>';
fullscreen.removeEventListener('click', exitFullscreen);
fullscreen.addEventListener('click', goFullscreen);
}
init(){
fullscreen.addEventListener('click', goFullscreen);
}
if(videoContainer){
init();
}
muted와 달리 현재 상태를 알 수 없어서 goFullscreen과 exitFullscreen 두개의 함수를 만들어서 eventListener를 지우고 추가하면서 fullscreen process를 구축하였습니다.