Skip to content

Commit

Permalink
fix: return top and left positions too
Browse files Browse the repository at this point in the history
  • Loading branch information
teclone committed Feb 28, 2020
1 parent 9956880 commit 5ae756b
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1053,8 +1053,10 @@ export const getScrollPositions = (elem?: HTMLElement | null) => {
*/
export const getScrolledPercentages = (elem?: HTMLElement | null) => {
const result = {
x: 0,
y: 0,
top: 0,
left: 0,
xPercent: 0,
yPercent: 0,
};

const amountToScroll = (scrollSize: number, clientSize: number) => {
Expand All @@ -1065,8 +1067,13 @@ export const getScrolledPercentages = (elem?: HTMLElement | null) => {
const scrollPositions = getScrollPositions(elem);
const clientSize = getClientSize(elem);

result.x = scrollPositions.left / amountToScroll(scrollSize.width, clientSize.width);
result.y = scrollPositions.top / amountToScroll(scrollSize.height, clientSize.height);
result.top = scrollPositions.top;
result.left = scrollPositions.left;

result.xPercent =
scrollPositions.left / amountToScroll(scrollSize.width, clientSize.width);
result.yPercent =
scrollPositions.top / amountToScroll(scrollSize.height, clientSize.height);

return result;
};

0 comments on commit 5ae756b

Please sign in to comment.