Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

pullRequestSummaryScroll.logic.ts

14 lines561 Bytes

1const STICKY_EDGE_TOLERANCE_PX = 1;
2​
3export function sectionCollapseAnchorScrollTop(input: {
4 readonly scrollTop: number;
5 readonly viewportTop: number;
6 readonly sectionTop: number;
7 readonly headingTop: number;
8}): number | null {
9 const sectionHasScrolledPastViewport = input.sectionTop < input.viewportTop;
10 const headingIsPinned = input.headingTop <= input.viewportTop + STICKY_EDGE_TOLERANCE_PX;
11 if (!sectionHasScrolledPastViewport || !headingIsPinned) return null;
12​
13 return Math.max(0, input.scrollTop + input.sectionTop - input.viewportTop);