@@ -53,7 +53,18 @@ import PlayButton from "../assets/videos/play-button.svg";
53
53
filter: brightness(0.2);
54
54
}
55
55
56
- .playButton {
56
+ /* 隐藏所有浏览器的原生播放按钮 */
57
+ video::-webkit-media-controls-play-button,
58
+ video::-webkit-media-controls-start-playback-button,
59
+ video::-moz-media-controls-play-button {
60
+ display: none !important;
61
+ opacity: 0 !important;
62
+ pointer-events: none !important;
63
+ width: 0 !important;
64
+ height: 0 !important;
65
+ }
66
+
67
+ .play-button {
57
68
background: none;
58
69
position: absolute;
59
70
border: none;
@@ -64,15 +75,15 @@ import PlayButton from "../assets/videos/play-button.svg";
64
75
visibility: visible;
65
76
}
66
77
67
- .playButton -invisible {
78
+ .play-button -invisible {
68
79
visibility: hidden;
69
80
}
70
81
71
- .playButton :hover {
82
+ .play-button :hover {
72
83
transform: scale(1.1);
73
84
}
74
85
75
- .playButton img {
86
+ .play-button img {
76
87
width: clamp(3rem, 10vw, 6rem);
77
88
}
78
89
@@ -105,22 +116,22 @@ import PlayButton from "../assets/videos/play-button.svg";
105
116
<script >
106
117
document.addEventListener("DOMContentLoaded", () => {
107
118
const video = document.querySelector("video") as HTMLVideoElement;
108
- const playButton = document.getElementsByClassName("playButton ")[0] as HTMLButtonElement;
119
+ const playButton = document.getElementsByClassName("play-button ")[0] as HTMLButtonElement;
109
120
let isPlaying = false;
110
121
111
122
video.classList.add("video-not-interactive");
112
123
113
124
playButton.addEventListener("click", () => {
114
125
video.play();
115
126
isPlaying = true;
116
- playButton.classList.add("playButton -invisible");
127
+ playButton.classList.add("play-button -invisible");
117
128
video.classList.remove("video-not-interactive");
118
129
});
119
130
120
131
video.addEventListener("pause", () => {
121
132
if (isPlaying) {
122
133
isPlaying = false;
123
- playButton.classList.remove("playButton -invisible");
134
+ playButton.classList.remove("play-button -invisible");
124
135
video.classList.add("video-not-interactive");
125
136
}
126
137
});
@@ -136,7 +147,7 @@ import PlayButton from "../assets/videos/play-button.svg";
136
147
<video controls poster ={ Poster .src } muted playsinline >
137
148
<source src ={ videoUrl } type =" video/mp4" />
138
149
</video >
139
- <button class =" playButton " >
150
+ <button class =" play-button " >
140
151
<Image src ={ PlayButton } alt =" Play button" />
141
152
</button >
142
153
</div >
0 commit comments