Skip to content

Commit 0769ffe

Browse files
committed
Red pill: scroll after shatter video finishes; hero video resets when scrolled away
1 parent 927b0d8 commit 0769ffe

2 files changed

Lines changed: 48 additions & 8 deletions

File tree

docs/index.html

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,30 @@
172172
setTimeout(()=>document.getElementById('scroll-wrap').classList.remove('shake'),400);
173173
const hint=document.getElementById('pill-hint');
174174
if(hint)hint.style.opacity='0';
175-
setTimeout(()=>{
176-
const target=type==='blue'?'#act-blue':'#act-red';
177-
document.querySelector(target).scrollIntoView({behavior:'smooth'});
178-
},400);
175+
176+
if(type==='blue'){
177+
setTimeout(()=>document.querySelector('#act-blue').scrollIntoView({behavior:'smooth'}),400);
178+
}else{
179+
// Red: wait for shatter video to nearly finish, then scroll
180+
const vShatter=document.getElementById('vid-hero-shatter');
181+
if(vShatter&&vShatter.duration){
182+
const waitMs=Math.max(0,(vShatter.duration-vShatter.currentTime-0.5)*1000);
183+
setTimeout(()=>document.querySelector('#act-red').scrollIntoView({behavior:'smooth'}),waitMs);
184+
}else{
185+
setTimeout(()=>document.querySelector('#act-red').scrollIntoView({behavior:'smooth'}),5000);
186+
}
187+
}
188+
189+
// When hero leaves viewport, reset video back to calm
190+
const resetObs=new IntersectionObserver(entries=>{
191+
if(!entries[0].isIntersecting){
192+
const vc=document.getElementById('vid-hero-calm');
193+
const vs=document.getElementById('vid-hero-shatter');
194+
if(vc&&vs){vc.style.opacity='1';vs.style.opacity='0'}
195+
resetObs.disconnect();
196+
}
197+
},{threshold:0});
198+
resetObs.observe(document.getElementById('act-choice'));
179199
});
180200

181201
let pmx=0,pmy=0;

mofa-website/src/pages/index.astro

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,10 +544,30 @@ let cx=0,cy=0;
544544
setTimeout(()=>document.getElementById('scroll-wrap').classList.remove('shake'),400);
545545
const hint=document.getElementById('pill-hint');
546546
if(hint)hint.style.opacity='0';
547-
setTimeout(()=>{
548-
const target=type==='blue'?'#act-blue':'#act-red';
549-
document.querySelector(target).scrollIntoView({behavior:'smooth'});
550-
},400);
547+
548+
if(type==='blue'){
549+
setTimeout(()=>document.querySelector('#act-blue').scrollIntoView({behavior:'smooth'}),400);
550+
}else{
551+
// Red: wait for shatter video to nearly finish, then scroll
552+
const vShatter=document.getElementById('vid-hero-shatter');
553+
if(vShatter&&vShatter.duration){
554+
const waitMs=Math.max(0,(vShatter.duration-vShatter.currentTime-0.5)*1000);
555+
setTimeout(()=>document.querySelector('#act-red').scrollIntoView({behavior:'smooth'}),waitMs);
556+
}else{
557+
setTimeout(()=>document.querySelector('#act-red').scrollIntoView({behavior:'smooth'}),5000);
558+
}
559+
}
560+
561+
// When hero leaves viewport, reset video back to calm
562+
const resetObs=new IntersectionObserver(entries=>{
563+
if(!entries[0].isIntersecting){
564+
const vc=document.getElementById('vid-hero-calm');
565+
const vs=document.getElementById('vid-hero-shatter');
566+
if(vc&&vs){vc.style.opacity='1';vs.style.opacity='0'}
567+
resetObs.disconnect();
568+
}
569+
},{threshold:0});
570+
resetObs.observe(document.getElementById('act-choice'));
551571
});
552572

553573
let pmx=0,pmy=0;

0 commit comments

Comments
 (0)