File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,11 @@ export function ReaderDepthTracker() {
2929 // calculate the progress based on the scroll position
3030 const scrollPosition = window . scrollY ;
3131 const totalHeight = document . documentElement . scrollHeight - window . innerHeight ;
32- const progress = Math . floor ( ( scrollPosition / totalHeight ) * 100 ) ;
32+ let progress = Math . floor ( ( scrollPosition / totalHeight ) * 100 ) ;
33+ // it's hard to trigger the 100% milestone, so we'll just assume beyond 95%
34+ if ( progress > 95 ) {
35+ progress = 100 ;
36+ }
3337
3438 // find the biggest milestone that has not been reached yet
3539 const milestone = milestones . findLast (
@@ -51,11 +55,11 @@ export function ReaderDepthTracker() {
5155 sendProgressToPlausible ( 100 ) ;
5256 return ( ) => { } ;
5357 }
54- const debouncedTrackProgress = debounce ( trackProgress , 50 ) ;
58+ const debouncedTrackProgress = debounce ( trackProgress , 20 ) ;
5559
56- window . addEventListener ( 'scrollend ' , debouncedTrackProgress ) ;
60+ window . addEventListener ( 'scroll ' , debouncedTrackProgress ) ;
5761 return ( ) => {
58- window . removeEventListener ( 'scrollend ' , debouncedTrackProgress ) ;
62+ window . removeEventListener ( 'scroll ' , debouncedTrackProgress ) ;
5963 } ;
6064 } ) ;
6165 // do not render anything
You can’t perform that action at this time.
0 commit comments