@@ -4,6 +4,104 @@ const q = (s, el=document)=>el.querySelector(s);
44const qa = ( s , el = document ) => [ ...el . querySelectorAll ( s ) ] ;
55const clamp = ( x , a , b ) => Math . max ( a , Math . min ( b , x ) ) ;
66
7+ /* ===== WeChat Browser Video Fix ===== */
8+ // 检测是否是微信浏览器
9+ function isWeChat ( ) {
10+ return / M i c r o M e s s e n g e r / 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 */
8106function 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