From 3d73903353bd414608e6c373d9d18a481f5f1536 Mon Sep 17 00:00:00 2001 From: Ramakrishna Date: Sun, 13 Oct 2019 22:12:43 +0530 Subject: [PATCH] Added correct calculation of offset Fixes https://github.com/CassetteRocks/react-infinite-scroller/issues/230 --- src/InfiniteScroll.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/InfiniteScroll.js b/src/InfiniteScroll.js index b08637e..7893579 100644 --- a/src/InfiniteScroll.js +++ b/src/InfiniteScroll.js @@ -204,7 +204,15 @@ export default class InfiniteScroll extends Component { } else if (this.props.isReverse) { offset = parentNode.scrollTop; } else { - offset = el.scrollHeight - parentNode.scrollTop - parentNode.clientHeight; + let relativeHeight = + el.getBoundingClientRect().top + + parentNode.scrollTop - + parentNode.getBoundingClientRect().top; + offset = + relativeHeight + + el.scrollHeight - + parentNode.scrollTop - + parentNode.clientHeight; } // Here we make sure the element is visible as well as checking the offset