Skip to content

Commit 94205ba

Browse files
committed
Measure the height of the video and set the absolute positioning of the cues by % off of that.
1 parent 49dad50 commit 94205ba

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

dotcom-rendering/src/components/LoopVideo.importable.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -489,16 +489,20 @@ export const LoopVideo = ({
489489
const handleLoadedMetadata = () => {
490490
if (!vidRef.current) return;
491491

492-
console.log('textTracks', vidRef.current.textTracks);
493-
494492
const track = vidRef.current.textTracks[0];
495493
if (!track?.cues) return;
496-
497-
console.log('cues', track.cues);
494+
const pxFromBottom = 16;
495+
const videoHeight =
496+
vidRef.current.getBoundingClientRect().height ||
497+
vidRef.current.clientHeight ||
498+
height;
499+
const percentFromTop =
500+
((videoHeight - pxFromBottom) / videoHeight) * 100;
498501

499502
for (const cue of Array.from(track.cues)) {
500503
if (cue instanceof VTTCue) {
501-
cue.line = -2;
504+
cue.snapToLines = false;
505+
cue.line = percentFromTop;
502506
}
503507
}
504508
};

0 commit comments

Comments
 (0)