Skip to content

Commit 42ea8aa

Browse files
kevinten10claude
andcommitted
feat: 添加视频声音切换按钮 — 点击取消静音播放配音和音乐
浏览器要求 autoplay 视频必须 muted,添加 Apple 风格毛玻璃按钮 让用户点击开启声音。点击后视频从头播放,按钮变蓝色确认状态。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 97c3319 commit 42ea8aa

2 files changed

Lines changed: 62 additions & 1 deletion

File tree

content/zh/_index.html

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,13 @@ <h2 class="capa-section-title">眼见为实。</h2>
5252
</p>
5353
</div>
5454
<div class="capa-video__player capa-reveal capa-reveal-delay-1">
55-
<video autoplay muted loop playsinline preload="metadata">
55+
<video id="capaVideo" autoplay muted loop playsinline preload="metadata">
5656
<source src="/videos/capa-demo-final.mp4" type="video/mp4">
5757
</video>
58+
<button class="capa-video__sound" id="soundToggle" aria-label="开启声音">
59+
<i class="fas fa-volume-mute" id="soundIcon"></i>
60+
<span id="soundLabel">点击开启声音</span>
61+
</button>
5862
</div>
5963
</section>
6064

@@ -205,4 +209,27 @@ <h4>联系我们</h4>
205209
}, { threshold: 0.1, rootMargin: '0px 0px -60px 0px' });
206210
els.forEach(function(el) { observer.observe(el); });
207211
})();
212+
213+
// Video sound toggle
214+
(function() {
215+
var video = document.getElementById('capaVideo');
216+
var btn = document.getElementById('soundToggle');
217+
var icon = document.getElementById('soundIcon');
218+
var label = document.getElementById('soundLabel');
219+
if (!video || !btn) return;
220+
btn.addEventListener('click', function() {
221+
if (video.muted) {
222+
video.muted = false;
223+
video.currentTime = 0;
224+
icon.className = 'fas fa-volume-up';
225+
label.textContent = '声音已开启';
226+
btn.classList.add('is-unmuted');
227+
} else {
228+
video.muted = true;
229+
icon.className = 'fas fa-volume-mute';
230+
label.textContent = '点击开启声音';
231+
btn.classList.remove('is-unmuted');
232+
}
233+
});
234+
})();
208235
</script>

layouts/partials/hooks/head-end.html

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@
353353
background: #000;
354354
box-shadow: 0 20px 60px rgba(0,0,0,0.12), 0 0 0 0.5px rgba(0,0,0,0.06);
355355
transition: transform 0.6s var(--apple-ease), box-shadow 0.6s var(--apple-ease);
356+
position: relative;
356357
}
357358
.capa-video__player:hover {
358359
transform: scale(1.01);
@@ -365,6 +366,39 @@
365366
display: block;
366367
}
367368

369+
.capa-video__sound {
370+
position: absolute;
371+
bottom: 20px;
372+
right: 20px;
373+
display: flex;
374+
align-items: center;
375+
gap: 8px;
376+
padding: 8px 16px;
377+
background: rgba(0,0,0,0.6);
378+
backdrop-filter: blur(12px);
379+
-webkit-backdrop-filter: blur(12px);
380+
border: 1px solid rgba(255,255,255,0.15);
381+
border-radius: 980px;
382+
color: rgba(255,255,255,0.9);
383+
font-family: var(--apple-font);
384+
font-size: 0.78rem;
385+
font-weight: 500;
386+
cursor: pointer;
387+
transition: all 0.3s var(--apple-ease);
388+
z-index: 3;
389+
}
390+
.capa-video__sound:hover {
391+
background: rgba(0,0,0,0.8);
392+
border-color: rgba(255,255,255,0.25);
393+
}
394+
.capa-video__sound i {
395+
font-size: 0.9rem;
396+
}
397+
.capa-video__sound.is-unmuted {
398+
background: rgba(0,113,227,0.7);
399+
border-color: rgba(0,113,227,0.5);
400+
}
401+
368402
/* ---------- Features ---------- */
369403
.capa-features {
370404
padding: 40px 24px 100px;

0 commit comments

Comments
 (0)