@@ -37,7 +37,7 @@ export function usePercentageSeen(element: HTMLElement | null, onChange: (percen
3737 const calcPercentage =
3838 ( overTopEdge ? elementOffsetTop + elementHeight - topEdge : bottomEdge - elementOffsetTop ) / elementHeight
3939 // Restrict the range to between 0 and 1
40- const percentage = clampValue ( 0 , 1 , calcPercentage )
40+ const percentage = Math . round ( clampValue ( 0 , 1 , calcPercentage ) * 100 ) / 100
4141 onChange ( percentage )
4242 } )
4343
@@ -67,7 +67,7 @@ export function useYPercentageOnScreen(
6767 const trigger = elementPos - viewportHeight
6868 // now calculate the element's position y on screen, and get percentage y
6969 // also restrict range to between 0 and 1
70- const percentage = clampValue ( 0 , 1 , ( scrollPos - trigger ) / viewportHeight )
70+ const percentage = Math . round ( clampValue ( 0 , 1 , ( scrollPos - trigger ) / viewportHeight ) * 100 ) / 100
7171 onChange ( percentage )
7272 } )
7373
@@ -80,8 +80,11 @@ export function useScrollPosition(onChange: ({ yPos, yPercentage }: { yPos: numb
8080 scrollHooks . push ( ( ) => {
8181 const yPos = window . scrollY
8282 const yPercentage =
83- document . documentElement . scrollTop /
84- ( document . documentElement . scrollHeight - document . documentElement . clientHeight )
83+ Math . round (
84+ ( document . documentElement . scrollTop /
85+ ( document . documentElement . scrollHeight - document . documentElement . clientHeight ) ) *
86+ 100
87+ ) / 100
8588 onChange ( { yPos, yPercentage } )
8689 } )
8790
0 commit comments