티스토리 뷰
동영상을 직접 스타일링 하기 위해 구현한 코드다. 오늘 날짜로 TIL이 2개인데, 글이 길어질까봐 글을 나눴다.
const fullScrnBtn = document.getElementById("jsFullScreen");
const currentTime = document.getElementById("currentTime");
const totalTime = document.getElementById("totalTime");
function exitFullScreen() {
fullScrnBtn.innerHTML = '<i class="fas fa-expand"></i>';
fullScrnBtn.addEventListener("click", goFullScreen);
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
}
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();
}
fullScrnBtn.innerHTML = '<i class="fas fa-compress"></i>';
fullScrnBtn.removeEventListener("click", goFullScreen);
fullScrnBtn.addEventListener("click", exitFullScreen);
}
const formatDate = seconds => {
const secondsNumber = parseInt(seconds, 10);
console.log(seconds);
let hours = Math.floor(secondsNumber / 3600);
let minutes = Math.floor((secondsNumber - hours * 3600) / 60);
let totalSeconds = secondsNumber - hours * 3600 - minutes * 60;
if (hours < 10) {
hours = `0${hours}`;
}
if (minutes < 10) {
minutes = `0${minutes}`;
}
if (seconds < 10) {
totalSeconds = `0${totalSeconds}`;
}
return `${hours}:${minutes}:${totalSeconds}`;
};
function getCurrentTime() {
currentTime.innerHTML = formatDate(videoPlayer.currentTime);
}
function setTotalTime() {
const totalTimeString = formatDate(videoPlayer.duration);
totalTime.innerHTML = totalTimeString;
setInterval(getCurrentTime, 1000);
}
video에 지원되는 기능이 굉장히 많았다. 풀스크린이나, 전체화면 취소나 이미 Video에 내장되어 있는 함수들이 있어
크게 해줄 게 없었고, 풀스크린이 되었을 때 removeEvent, 아이콘 변경 등의 작업만 해주면 됐다.
Video의 시간도 내장 데이터가 있어 손 쉽게 구현을 할 수 있다는 걸 오늘에서야 알았다. 유튜브나 트위치 등
보면 다 어떻게 구현할까 생각만 했지, 이렇게 쉬운 줄은 전혀 몰랐다.
'TIL' 카테고리의 다른 글
2020-07-08 Register API (0) | 2020.07.08 |
---|---|
2020-07-06 Volume & Modal Router (0) | 2020.07.06 |
2020-07-02 Vue.js D-day Counter 공통 컴포넌트 (0) | 2020.07.02 |
2020-07-01 Customize Video Player (0) | 2020.07.01 |
2020-06-30 Node.js 라우터 가드 (0) | 2020.06.30 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- vue3
- 자바스크립트
- vuetify
- vue.js
- Core Components
- pinia
- backend
- 포트폴리오
- pagination
- CORS
- NUXT
- react native
- react-query
- 타입스크립트
- typescript
- react
- Cypress
- Redux
- Store
- 호이스팅
- react query
- composition
- 퍼블리셔
- three.js
- frontend
- e2e
- JS
- vuex
- vue
- Front
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
글 보관함