Skip to content

Commit 1c438cb

Browse files
committed
fix: improve video controls handling and fix the odd behaviour when jumping to different points by clicking the progress bar
1 parent d1fd796 commit 1c438cb

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

apps/website/src/sections/Spotlight.astro

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,6 @@ import PlayButton from "../assets/videos/play-button.svg";
5353
filter: brightness(0.2);
5454
}
5555

56-
video::-webkit-media-controls-play-button,
57-
video::-webkit-media-controls-start-playback-button,
58-
video::-moz-media-controls-play-button {
59-
display: none !important;
60-
opacity: 0 !important;
61-
pointer-events: none !important;
62-
width: 0 !important;
63-
height: 0 !important;
64-
}
65-
6656
.play-button {
6757
background: none;
6858
position: absolute;
@@ -116,24 +106,37 @@ import PlayButton from "../assets/videos/play-button.svg";
116106
document.addEventListener("DOMContentLoaded", () => {
117107
const video = document.querySelector("video") as HTMLVideoElement;
118108
const playButton = document.getElementsByClassName("play-button")[0] as HTMLButtonElement;
119-
let isPlaying = false;
109+
let isUserPause = false;
120110

111+
video.removeAttribute("controls");
121112
video.classList.add("video-not-interactive");
122113

123114
playButton.addEventListener("click", () => {
124115
video.play();
125-
isPlaying = true;
126116
playButton.classList.add("play-button-invisible");
127117
video.classList.remove("video-not-interactive");
118+
video.setAttribute("controls", "true");
119+
isUserPause = true;
128120
});
129121

130122
video.addEventListener("pause", () => {
131-
if (isPlaying) {
132-
isPlaying = false;
123+
if (isUserPause == true) {
133124
playButton.classList.remove("play-button-invisible");
134125
video.classList.add("video-not-interactive");
126+
video.removeAttribute("controls");
135127
}
136128
});
129+
130+
video.addEventListener("click", (e) => {
131+
const target = e.target as HTMLVideoElement;
132+
if (target === video && video.hasAttribute("controls")) {
133+
isUserPause = true;
134+
}
135+
});
136+
137+
video.addEventListener("seeking", () => {
138+
isUserPause = false;
139+
});
137140
});
138141
</script>
139142

0 commit comments

Comments
 (0)