Skip to content

Scrolling Within An Index #542

Answered by inokawa
pcbowers asked this question in Q&A
Nov 10, 2024 · 1 comments · 3 replies
Discussion options

You must be logged in to vote

This seems to work without the opacity and scrollend controll, as far as I tested. scrollToIndex will be completed without repaint, so you can schedule it again with sentence.offsetTop just before paint.

function scrollToChapter(chapterId: number, sentenceId?: string) {
  if (!virtualizer) return;
  virtualizer.scrollToIndex(chapterId - 1);

  if (sentenceId) {
    requestAnimationFrame(() => {
      const sentence = document.getElementById(sentenceId);
      if (!sentence) return;
      virtualizer.scrollToIndex(chapterId - 1, { offset: sentence.offsetTop });
    });
  }
}

There are no good API to wait for scrollToIndex ends for now. I may change scrollToIndex to return promise to wait f…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@inokawa
Comment options

Answer selected by pcbowers
@pcbowers
Comment options

@inokawa
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants