@@ -44,12 +44,53 @@ document.querySelectorAll('a[href^="#"]').forEach(anchor => {
4444
4545document . addEventListener ( "DOMContentLoaded" , function ( ) {
4646 const heroVideo = document . querySelector ( "#heading-container .hero-video" ) ;
47+ const heroSection = document . querySelector ( "#heading-container" ) ;
48+ const isMobileViewport = window . matchMedia ( "(max-width: 900px)" ) . matches ;
49+
50+ function safePlayVideo ( videoEl ) {
51+ if ( ! videoEl ) {
52+ return ;
53+ }
54+ const playPromise = videoEl . play ( ) ;
55+ if ( playPromise && typeof playPromise . catch === "function" ) {
56+ playPromise . catch ( function ( ) {
57+ // Ignore autoplay interruptions from browser policies.
58+ } ) ;
59+ }
60+ }
61+
4762 if ( heroVideo ) {
4863 heroVideo . addEventListener ( "loadedmetadata" , function ( ) {
4964 heroVideo . currentTime = 5.5 ;
5065 } , { once : true } ) ;
5166 }
5267
68+ if ( heroVideo && heroSection && isMobileViewport && "IntersectionObserver" in window ) {
69+ let heroIsVisible = true ;
70+ const observer = new IntersectionObserver ( function ( entries ) {
71+ entries . forEach ( function ( entry ) {
72+ heroIsVisible = entry . isIntersecting && entry . intersectionRatio >= 0.18 ;
73+ } ) ;
74+ if ( heroIsVisible ) {
75+ safePlayVideo ( heroVideo ) ;
76+ } else {
77+ heroVideo . pause ( ) ;
78+ }
79+ } , {
80+ threshold : [ 0 , 0.18 , 0.4 ]
81+ } ) ;
82+
83+ observer . observe ( heroSection ) ;
84+
85+ document . addEventListener ( "visibilitychange" , function ( ) {
86+ if ( document . hidden ) {
87+ heroVideo . pause ( ) ;
88+ } else if ( heroIsVisible ) {
89+ safePlayVideo ( heroVideo ) ;
90+ }
91+ } ) ;
92+ }
93+
5394 const heroIntroTargets = document . querySelectorAll ( [
5495 "#heading-container .container-left img" ,
5596 "#heading-container .container-left p" ,
0 commit comments