Skip to content

Commit 2ec1156

Browse files
update
1 parent a60f6f4 commit 2ec1156

File tree

3 files changed

+161
-0
lines changed

3 files changed

+161
-0
lines changed

WECHAT_FIX.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# 微信浏览器视频播放修复
2+
3+
## 问题
4+
微信浏览器禁用了视频自动播放功能,导致网页中的视频显示全黑无法播放。
5+
6+
## 解决方案
7+
已添加微信浏览器检测和点击播放功能。
8+
9+
### 工作原理
10+
1. **自动检测微信浏览器**:通过 User-Agent 检测
11+
2. **移除自动播放**:在微信中禁用 autoplay
12+
3. **显示播放提示**:添加"点击播放"覆盖层
13+
4. **点击即播**:用户点击视频后开始播放
14+
15+
### 修改的文件
16+
- `assets/js/main.js` - 添加微信检测和播放逻辑
17+
- `assets/css/style.css` - 添加播放提示动画
18+
19+
### 功能特性
20+
✅ 自动检测微信浏览器
21+
✅ 显示美观的播放按钮
22+
✅ 点击/触摸即可播放
23+
✅ 播放后自动隐藏提示
24+
✅ 不影响其他浏览器的自动播放
25+
✅ 支持页面所有视频
26+
27+
### 测试方法
28+
1. 在微信中打开网页
29+
2. 视频上会显示"▶ 点击播放"提示
30+
3. 点击视频即可播放
31+
4. 播放后提示消失
32+
33+
### 备用方案
34+
如果点击单个视频无效,首次触摸屏幕任意位置会尝试播放所有视频。
35+
36+
---
37+
38+
**完成日期**:2026年2月10日

assets/css/style.css

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,6 +1460,30 @@ h1, h2, h3, p, li, .caption, .small {
14601460

14611461
main .caption { opacity: 1 !important; }
14621462

1463+
/* ===== WeChat Video Play Hint ===== */
1464+
.wechat-play-hint {
1465+
transition: opacity 0.3s ease;
1466+
}
1467+
1468+
.wechat-play-hint:hover {
1469+
background: rgba(0, 0, 0, 0.75) !important;
1470+
}
1471+
1472+
.wechat-play-hint .play-icon {
1473+
animation: pulse 2s ease-in-out infinite;
1474+
}
1475+
1476+
@keyframes pulse {
1477+
0%, 100% {
1478+
transform: scale(1);
1479+
opacity: 1;
1480+
}
1481+
50% {
1482+
transform: scale(1.1);
1483+
opacity: 0.8;
1484+
}
1485+
}
1486+
14631487
@media (max-width: 768px) {
14641488
.hero-overlay .hero-links {
14651489
margin-top: 10px; /* 可选:按钮离上方稍微留一点 */

assets/js/main.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,104 @@ const q = (s, el=document)=>el.querySelector(s);
44
const qa = (s, el=document)=>[...el.querySelectorAll(s)];
55
const clamp=(x,a,b)=>Math.max(a,Math.min(b,x));
66

7+
/* ===== WeChat Browser Video Fix ===== */
8+
// 检测是否是微信浏览器
9+
function isWeChat(){
10+
return /MicroMessenger/i.test(navigator.userAgent);
11+
}
12+
13+
// 微信浏览器视频播放修复
14+
function setupWeChatVideoFix(){
15+
if(!isWeChat()) return;
16+
17+
console.log('WeChat browser detected - setting up video click-to-play');
18+
19+
const videos = qa('video');
20+
21+
videos.forEach(video => {
22+
// 移除自动播放
23+
video.removeAttribute('autoplay');
24+
video.pause();
25+
26+
// 添加播放提示覆盖层
27+
const wrapper = video.parentElement;
28+
if(!wrapper) return;
29+
30+
// 检查是否已经有播放提示
31+
if(wrapper.querySelector('.wechat-play-hint')) return;
32+
33+
const playHint = document.createElement('div');
34+
playHint.className = 'wechat-play-hint';
35+
playHint.innerHTML = `
36+
<div class="play-icon">▶</div>
37+
<div class="play-text">点击播放</div>
38+
`;
39+
playHint.style.cssText = `
40+
position: absolute;
41+
top: 0;
42+
left: 0;
43+
width: 100%;
44+
height: 100%;
45+
display: flex;
46+
flex-direction: column;
47+
align-items: center;
48+
justify-content: center;
49+
background: rgba(0, 0, 0, 0.6);
50+
color: white;
51+
cursor: pointer;
52+
z-index: 10;
53+
backdrop-filter: blur(4px);
54+
`;
55+
56+
const playIcon = playHint.querySelector('.play-icon');
57+
playIcon.style.cssText = `
58+
font-size: 48px;
59+
margin-bottom: 8px;
60+
`;
61+
62+
const playText = playHint.querySelector('.play-text');
63+
playText.style.cssText = `
64+
font-size: 14px;
65+
font-weight: 600;
66+
`;
67+
68+
// 确保 wrapper 是 relative 定位
69+
const wrapperPosition = window.getComputedStyle(wrapper).position;
70+
if(wrapperPosition === 'static'){
71+
wrapper.style.position = 'relative';
72+
}
73+
74+
wrapper.appendChild(playHint);
75+
76+
// 点击播放
77+
const playVideo = () => {
78+
video.play().then(() => {
79+
playHint.remove();
80+
}).catch(err => {
81+
console.error('Video play failed:', err);
82+
});
83+
};
84+
85+
playHint.addEventListener('click', playVideo);
86+
playHint.addEventListener('touchstart', playVideo);
87+
});
88+
89+
// 全局触摸事件(备用方案)
90+
let hasPlayedAny = false;
91+
const globalPlayHandler = () => {
92+
if(hasPlayedAny) return;
93+
hasPlayedAny = true;
94+
95+
videos.forEach(video => {
96+
if(video.paused){
97+
video.play().catch(() => {});
98+
}
99+
});
100+
};
101+
102+
document.addEventListener('touchstart', globalPlayHandler, {once: true, passive: true});
103+
}
104+
7105
/* Active nav - Enhanced */
8106
function setupActiveNav(){
9107
const sections = qa("section[id]");
@@ -538,6 +636,7 @@ window.addEventListener("load", ()=>{
538636
setupBackToTop();
539637
setupFadeInAnimations();
540638
setupActiveNav();
639+
setupWeChatVideoFix();
541640
});
542641

543642
/* ===== Hero video interactions ===== */

0 commit comments

Comments
 (0)