Aviad Aviad - 1 month ago 6
AngularJS Question

Scroll event won't fire what so ever

I have a (fairly simple) issue and i'm breaking my head over it.

The issue is pretty simple -

scroll
event won't fire (ever).

I'm writing this angular project, so I've tried the following:

angular.element($window).bind('scroll', ()=> {
console.log('scroll!');
if (!scope.scrollPosition) {
scope.scrollPosition = 0;
}
// Alerting for test cause wtf is going on
scope.boolChangeClass = this.pageYOffset > 600 ? alert(true) : alert(false);
scope.scrollPosition = this.pageYOffset;
scope.$apply();
}
);


but nothing happened. (assume
$window
is intact and that i'm using webpack etc.)
This example works great if I change the
scroll
to
click
. weird.

So I've tried vanilla~~!

window.addEventListener('scroll',function(){
console.log('test')
})


This attempt works on every other website except mine (gotta admit it's classic).

So - has anyone ever dealt with this and knows what's going on?

I assume that some other element is consuming this event at early stage thus not letting it bubble up. Yet this is just an assumption.'

Would love to understand this :)

=== EDIT ===

I've tried to see all the fired events using
monitorEvents(window)
(using Chrome) and I see every event that's being fire except the scroll..

Answer

Looks like it's the body element that is scrolling. Try adding the following code in the console.

document.body.addEventListener('scroll',function(){
  console.log('test')
})