Skip to content

Commit

Permalink
Transcript scroll fix (#306)
Browse files Browse the repository at this point in the history
* Scroll current line into Transcript component's view w/ playback w/o scrolling the page

* Scroll to active transcript line immediately when it is outside of view
  • Loading branch information
Dananji authored Dec 6, 2023
1 parent 61614b2 commit 2a54d70
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/components/Transcript/Transcript.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ const Transcript = ({ playerID, manifestUrl, transcripts = [] }) => {
const start = parseFloat(tr.getAttribute('starttime'));
const end = parseFloat(tr.getAttribute('endtime'));
if (currentTime >= start && currentTime <= end) {
!tr.classList.contains('active')
? autoScrollAndHighlight(currentTime, start, end, tr)
: null;
autoScrollAndHighlight(currentTime, start, end, tr);
} else {
// remove highlight
tr.classList.remove('active');
Expand Down Expand Up @@ -299,7 +297,11 @@ const Transcript = ({ playerID, manifestUrl, transcripts = [] }) => {
return;
}

tr.scrollIntoView({ behavior: 'smooth', block: 'center' });
// Scroll the transcript line to the center of the
// transcript component view
transcriptContainerRef.current.scrollTop =
textTopOffset -
transcriptContainerRef.current.clientHeight;
};

/**
Expand Down

0 comments on commit 2a54d70

Please sign in to comment.