Skip to content
This repository was archived by the owner on Nov 5, 2023. It is now read-only.

Commit 1e4529c

Browse files
committed
fix: scrollTop calculation
1 parent 93ef9aa commit 1e4529c

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/pipeline.ts

+23-5
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,30 @@ export function pipeline({
276276
([scrollTo, { columns, itemHeightWithGap }, rootEl]) => {
277277
const verticalScrollEl = getVerticalScrollParent(rootEl);
278278

279+
const computedStyle = window.getComputedStyle(rootEl);
280+
281+
const gridPaddingTop = parseInt(
282+
computedStyle.getPropertyValue("padding-top")
283+
);
284+
const gridBoarderTop = parseInt(
285+
computedStyle.getPropertyValue("border-top")
286+
);
287+
288+
const topToGridContainer =
289+
rootEl instanceof HTMLElement &&
290+
verticalScrollEl instanceof HTMLElement
291+
? rootEl.offsetTop - verticalScrollEl.offsetTop
292+
: 0;
293+
294+
// The offset within the scroll container
279295
const scrollTop =
280-
// The offset within the grid container
281-
Math.floor((scrollTo - 1) / columns) * itemHeightWithGap +
282-
// Offset to the offsetParent
283-
(rootEl instanceof HTMLElement ? rootEl.offsetTop : 0);
284-
296+
// row count * row height
297+
Math.floor(scrollTo / columns) * itemHeightWithGap +
298+
// top to the scroll container
299+
topToGridContainer +
300+
// the padding + boarder top of grid
301+
gridPaddingTop +
302+
gridBoarderTop;
285303
return [verticalScrollEl, scrollTop];
286304
}
287305
)

0 commit comments

Comments
 (0)