webta.st.ic
webta.st.ic

Reputation: 5169

Detect if user is scrolling within a div

I searched for a way to detect if a user is scrolling within a div with angularjs. I looked on their documentation (https://docs.angularjs.org/api?PHPSESSID=cae8e98e7ca559b4605d75c813b358ee) and searched something like ng-click, but I didn't find anything regarding scrolling there. Is there really no easy way to do this? I would like to do something like this:

<div ng-scroll="ctrl.doSomething()">
</div>

I know, ng-scroll doesn't really exist. I just wrote it as an example. Any ideas to do this WITHOUT any external plugins or directives that I have to include?

Thanks.

Upvotes: 0

Views: 105

Answers (1)

Ameer Hamza
Ameer Hamza

Reputation: 606

you can make your own custome directive like:

.directive("ngScroll", function ($window) {
    return function(scope, element, attrs) {

        angular.element($window).bind("scroll", function() {
            console.log('do something!'); 
            scope.$apply();
        });
    };
});

and use it like this:

<div ng-scroll>
</div>

Upvotes: 3

Related Questions