diff options
Diffstat (limited to 'animism-align/frontend/app/views/viewer/transcript/transcript.container.js')
| -rw-r--r-- | animism-align/frontend/app/views/viewer/transcript/transcript.container.js | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/animism-align/frontend/app/views/viewer/transcript/transcript.container.js b/animism-align/frontend/app/views/viewer/transcript/transcript.container.js index b9caa69..88ed3b7 100644 --- a/animism-align/frontend/app/views/viewer/transcript/transcript.container.js +++ b/animism-align/frontend/app/views/viewer/transcript/transcript.container.js @@ -25,6 +25,7 @@ class Transcript extends Component { this.handleParagraphDoubleClick = this.handleParagraphDoubleClick.bind(this) this.handleMouseWheel = this.handleMouseWheel.bind(this) this.containerRef = React.createRef() + this.lastScroll = 0 } componentDidMount() { @@ -67,6 +68,7 @@ class Transcript extends Component { } updateScrollPosition(play_ts, forceScroll) { + if (this.state.scrolling) return const { paragraphs, windowHeight, currentParagraph } = this.state const scrollTop = this.containerRef.current.scrollTop if (!forceScroll && currentParagraph && floatInRange(currentParagraph.start_ts, play_ts, currentParagraph.end_ts)) return @@ -81,8 +83,19 @@ class Transcript extends Component { if (insideParagraph && nextParagraph) { // console.log(nextParagraph.scrollTop) if (!floatInRange(scrollTop, nextParagraph.scrollTop, scrollTop + windowHeight) || forceScroll) { - this.setState({ currentParagraph: nextParagraph, scrolling: true }) - this.scrollToParagraph(scrollTop, nextParagraph.scrollTop) + const now = Date.now() + // suppress double-scrolling + // suppress scroll if transcript is open and we've scrolled more than one screen-length away + if (!this.props.viewer.transcript || ( + now - this.lastScroll > 1200 && + Math.abs(scrollTop - nextParagraph.scrollTop) < this.state.windowHeight + )) { + this.lastScroll = now + this.scrollToParagraph(scrollTop, nextParagraph.scrollTop) + this.setState({ currentParagraph: nextParagraph, scrolling: true }) + } else { + this.setState({ currentParagraph: nextParagraph }) + } } else { this.setState({ currentParagraph: nextParagraph }) } @@ -90,6 +103,7 @@ class Transcript extends Component { } scrollToParagraph(scrollFrom, scrollTo) { + // suppress if already scrolling if (this.state.scrolling) return // console.log('scrolling!', scrollFrom, scrollTo) oktween.add({ @@ -125,6 +139,7 @@ class Transcript extends Component { handleMouseWheel(e) { e.stopPropagation() + this.lastScroll = Date.now() } render() { |
