What is the best way to run a JavaScript function when a user reaches a certain point on a web page?
            Asked
            
        
        
            Active
            
        
            Viewed 317 times
        
    1 Answers
0
            
            
        Check the offset of the document with document.documentElement.scrollTop
let called = false
document.addEventListener('scroll', e => {
  if (document.documentElement.scrollTop >= 500) {
    if (called) return
    called = true
    calledEvent()
  }
})
function calledEvent() {
  console.log('hello')
}body {
  height: 1000px;
} 
    
    
        Get Off My Lawn
        
- 34,175
- 38
- 176
- 338
 
    