playButton을 만들고 click evnetListener를 추가하여 재생 및 멈춤 기능을 만들어보겠습니다.
youtube
|views
|mixins
*|videoPlayer.pug
|assets
|js
*|videoPlayer.js
mixin videoPlayer(video = {})
.videoPlayer#jsVideoContainer
video#jsVideoPlayer(src=video.src)
.videoPlayer__controls
.videoPlayer__column
span#jsPlayButton
i.fas.fa-play
.videoPlayer__column
const videoContainer = document.querySelector("jsVideoContainer");
const videoPlayer = document.querySelector("#jsVideoPlayer");
const playButton = document.querySelector("#jsPlayButton");
function handlePlay(){
if(videoPlayer.paused){
videoPlayer.play();
playButton.innerHTML = '<i class="fas fa-pause"></i>';
}else{
videoPlayer.pause();
playButton.innerHTML = '<i class="fas fa-play"></i>';
}
}
function handleEnd(){
playButton.innerHTML = '<i class="fas fa-redo"></i>';
}
function init(){
playButton.addEventListener("click", handlePlay);
videoPlayer.addEventListener("ended", handleEnd);
}
if(videoContainer){
init();
}