Skip to content

Getting the scroll ratio #689

Closed Answered by KingSora
AHTOHO4 asked this question in Q&A
Discussion options

You must be logged in to vote

Good day @AHTOHO4 :)

This is a breaking change from overlayscrollbars v1.x to v2.x which is used under the hood of overlayscrollbars-react.
Since version 2 the library is not handling as many scrolling cases anymore and focuses only on the scrollbars.

You can calculate the ratio like this:

const { scrollOffsetElement } = osInstance.elements();
const { overflowAmount } = osInstance.state();

const scrollRatio = {
  x: (scrollOffsetElement.scrollLeft / overflowAmount.x) || 0,
  y: (scrollOffsetElement.scrollTop / overflowAmount.y) || 0,
};

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by AHTOHO4
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
2 participants
Converted from issue

This discussion was converted from issue #688 on November 13, 2024 16:14.