Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scroll event in AngularJS

I have a div with a scrollbar in it. Now I want to get an event, that triggers every time, the user scrolls.

Is that possible in AngularJS, or do I have to use jQuery for that?

Edit: I came up with following so far:

// JS
.directive('scroll', function() {
    return function(scope, element, attrs){

        angular.element(element).bind("scroll", function(){
            console.log(1);
        });
    };
});

// HTML
<div class="wrapper" style="height: 1550px" scroll>
[...]
</div>

But that does not work (I don't see any logs in my Firebug-Console).

like image 713
Tream Avatar asked Oct 27 '14 13:10

Tream


1 Answers

Solution for Angular 1.6:

.directive("scroll", function () {
return {
  link: function(scope, element, attrs) {
      element.bind("wheel", function() {
         console.log('Scrolled below header.');
      });
  }
}

})

Use "wheel" instead of "scroll". It takes me few hours to find.

like image 158
Sergey NN Avatar answered Nov 05 '22 10:11

Sergey NN