Thomas Allen
Thomas Allen

Reputation: 811

window.onscroll arrow function not working in Safari

I'm trying to detect window position on scroll but the window.onscroll = () => {} function doesn't work in Safari, although it works fine in Chrome and Firefox.

  myFunction() {
      window.onscroll = () =>{
        if(someCondition){
          ...do something
        } 
      }
  }

For some reason, Safari is the only browser where I can't log anything inside the window.onscroll function. I'm binding the function in the constructor and attaching it to a scroll event when the component mounts.

Does anyone know why this might be happening?

Upvotes: 0

Views: 1355

Answers (1)

Tanmay_vijay
Tanmay_vijay

Reputation: 619

Following script works from me on safari. Please try.

document.addEventListener('scroll',()=>{
  console.log('scrolling')
});
body {
height: 1200px;
background: blue;
}
<div>Scroll</div>

Upvotes: 1

Related Questions