MCPcopy Create free account
hub / github.com/github/docs / trackScroll

Function trackScroll

components/lib/events.ts:190–212  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

188}
189
190function trackScroll() {
191 // Throttle the calculations to no more than five per second
192 if (pauseScrolling) return
193 pauseScrolling = true
194 setTimeout(() => {
195 pauseScrolling = false
196 }, 200)
197
198 // Calculate where we are on the page
199 const scrollPixels = window.scrollY + window.innerHeight
200 const newScrollPosition = scrollPixels / document.documentElement.scrollHeight
201
202 // Count scroll flips
203 const newScrollDirection = Math.sign(newScrollPosition - scrollPosition)
204 if (newScrollDirection !== scrollDirection) scrollFlipCount++
205
206 // Update maximum scroll position reached
207 if (newScrollPosition > maxScrollY) maxScrollY = newScrollPosition
208
209 // Update before the next event
210 scrollDirection = newScrollDirection
211 scrollPosition = newScrollPosition
212}
213
214function sendPage() {
215 const pageEvent = sendEvent({ type: EventType.page })

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected