4

i'm using angularjs WITHOUT jquery, and trying to create scroll event listener.

tried this approach:

  $rootScope.$watch(function() {
    return $window.scrollY;
  }, function(n,o) {
    console.log('scroll');
  });

but it dosen't work..

I managed to achieve this goal using this technique to create resize listener:

  $rootScope.$watch(function() { // Listens to window size change
    return $window.innerWidth;
  }, function(n, o) {
    console.log('resize');
  });

is there a proper way to create pure angularjs scroll listener?

3 Answers 3

5

creating scroll event listener, 'The Angular Way', is actually very simple, using $window:

$window.onscroll = function() {
  console.log('scroll');
};
Sign up to request clarification or add additional context in comments.

1 Comment

Awesome!! this is what i have been looking for!!
1

try using onscroll event of javascript

Comments

0

Yes. your correct AngularJs provide $anchorScroll to scroll across the page but not that much effective. You can either go top or bottom like this. If you want scroll at particular position across vertical or horizontal $anchorScroll doesn't have that option. You have to go for normal javascript even for animation also. If you would like to explore more in Angular Scroll please have a look at this answer. Grate!!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.