-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
157 lines (139 loc) · 6.35 KB
/
app.js
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
console.log(
'Исходный проект: +10; Обязательный дополнительный фукционал: +10; Дополнительный функционал: кнопке звука добавил интерактивности при изменении звука, добавил попап с инструкцией по горячим клавишам и слайдер фоновый: +10'
);
const slidesList = document.querySelectorAll('.slidesList__item');
const popupBtn = document.querySelector('.popup-btn');
const leftSlide = document.querySelector('.leftBtn');
const rightSlide = document.querySelector('.rightBtn');
const popup = document.querySelector('.popup');
const video = document.querySelector('.player__video');
const videoPlayer = document.querySelector('.player');
const videoLibrary = document.querySelectorAll('.slider-panel li');
const play = document.querySelector('.player__play-button');
const audioBtn = document.querySelector('.player__sound-btn');
const fullScreenBtn = document.querySelector('.player__fullscreen-btn');
const videoScroll = document.querySelector('.progress__video');
const audioScroll = document.querySelector('.progress__volume');
let activeSlideIndex = 0;
let soundMute = false;
let mouseMove = false;
video.volume = 0.5;
videoScroll.value = 0;
function playVideo() {
if (video.paused) {
video.play();
play.firstElementChild.classList.value = 'fas fa-pause';
} else {
video.pause();
play.firstElementChild.classList.value = 'fas fa-play';
}
}
function clickAudioBtn() {
if (video.volume > 0) {
audioBtn.firstElementChild.classList.value = 'fas fa-volume-mute';
video.volume = 0;
soundMute = true;
} else if (+audioScroll.value >= 0.5) {
audioBtn.firstElementChild.classList.value = 'fas fa-volume-up';
video.volume = +audioScroll.value;
soundMute = false;
} else if (+audioScroll.value < 0.5 && +audioScroll.value > 0) {
audioBtn.firstElementChild.classList.value = 'fas fa-volume-down';
video.volume = +audioScroll.value;
soundMute = false;
} else {
audioBtn.firstElementChild.classList.value = 'fas fa-volume-off';
video.volume = +audioScroll.value;
soundMute = false;
}
}
function audioScrollEvent(e) {
if (e === 'ArrowUp') audioScroll.value = +audioScroll.value + 0.03;
if (e === 'ArrowDown') audioScroll.value = +audioScroll.value - 0.03;
const value = Math.floor(+audioScroll.value * 100);
audioScroll.style.background = `linear-gradient(to right, #24809E 0%, #24809E ${value}%, #C4C4C4 ${value}%, #C4C4C4 100%)`;
if (!soundMute) {
video.volume = +audioScroll.value;
value >= 50
? (audioBtn.firstElementChild.classList.value = 'fas fa-volume-up')
: (audioBtn.firstElementChild.classList.value = 'fas fa-volume-down');
if (value === 0) audioBtn.firstElementChild.classList.value = 'fas fa-volume-off';
} else if (soundMute) {
video.volume = 0;
}
}
function videoScrollEvent(e) {
const value = Math.round(+videoScroll.value);
const progressTime = (e.offsetX / videoScroll.offsetWidth) * video.duration;
videoScroll.style.background = `linear-gradient(to right, #24809E 0%, #24809E ${value}%, #C4C4C4 ${value}%, #C4C4C4 100%)`;
video.currentTime = progressTime;
}
function videoTimeUpdate() {
const percentage = (video.currentTime / video.duration) * 100;
videoScroll.style.background = `linear-gradient(to right, #24809E 0%, #24809E ${percentage}%, #C4C4C4 ${percentage}%, #C4C4C4 100%)`;
if (video.currentTime > 0) {
videoScroll.value = percentage;
} else {
videoScroll.value = 0;
}
}
function toggleScreen() {
document.fullscreenElement === null ? videoPlayer.requestFullscreen() : document.exitFullscreen();
}
function activeButtons(e) {
if (e.code === 'Space') playVideo();
if (e.code === 'KeyM') clickAudioBtn();
if (e.code === 'KeyF') toggleScreen();
if (e.code === 'ArrowRight') video.currentTime += 5;
if (e.code === 'ArrowLeft') video.currentTime -= 5;
if (e.code === 'ArrowUp') audioScrollEvent(e.code);
if (e.code === 'ArrowDown') audioScrollEvent(e.code);
if (e.code === 'Comma') {
video.playbackRate > 0.5 ? (video.playbackRate -= 0.1) : (video.playbackRate = 0.5);
}
if (e.code === 'Period') {
video.playbackRate < 2.1 ? (video.playbackRate += 0.1) : (video.playbackRate = 2.1);
}
if (e.code === 'Escape') {
popup.classList.remove('active');
popupBtn.classList.remove('active');
}
}
function leftSlideChanger() {
activeSlideIndex--;
if (activeSlideIndex < 0) activeSlideIndex = slidesList.length - 1;
document.body.style.background = `url(assets/img/background${activeSlideIndex}.jpg) no-repeat center`;
document.body.style.backgroundSize = `cover`;
}
function rightSlideChanger() {
activeSlideIndex++;
if (activeSlideIndex > slidesList.length - 1) activeSlideIndex = 0;
document.body.style.background = `url(assets/img/background${activeSlideIndex}.jpg) no-repeat center`;
document.body.style.backgroundSize = `cover`;
}
leftSlide.addEventListener('click', leftSlideChanger);
rightSlide.addEventListener('click', rightSlideChanger);
popupBtn.addEventListener('click', function () {
popup.classList.toggle('active');
popupBtn.classList.toggle('active');
});
play.addEventListener('click', playVideo);
video.addEventListener('click', playVideo);
video.addEventListener('timeupdate', videoTimeUpdate);
videoScroll.addEventListener('click', videoScrollEvent);
videoScroll.addEventListener('mousemove', e => mouseMove && videoScrollEvent(e));
videoScroll.addEventListener('mousedown', () => (mouseMove = true));
videoScroll.addEventListener('mouseup', () => (mouseMove = false));
audioBtn.addEventListener('click', clickAudioBtn);
audioScroll.addEventListener('input', audioScrollEvent);
fullScreenBtn.addEventListener('click', toggleScreen);
video.addEventListener('dblclick', toggleScreen);
document.addEventListener('keydown', e => activeButtons(e));
videoLibrary.forEach((item, index) =>
item.addEventListener('click', function () {
video.src = `assets/video/video${index}.mp4`;
play.firstElementChild.classList.value = 'fas fa-play';
video.poster = `assets/img/poster${index}.jpg`;
videoScroll.style.background = `linear-gradient(to right, #24809e 0%, #24809e 0%, #c4c4c4 0%, #c4c4c4 100%)`;
})
);