AngularJS 'scrollTop' Equivalent?
Answer :
$window.pageYOffset
This is property from service $window
I don't believe there's anything in Angular to get the scroll position. Just use plain vanilla JS.
You can retrieve the scrollTop property on any element.
https://developer.mozilla.org/en-US/docs/Web/API/Element.scrollTop
document.body.scrollTop
Fiddle for you: http://jsfiddle.net/cdwgsbq5/
Inject the $window into your controller and you can get the scroll position on scroll
var windowEl = angular.element($window); var handler = function() { console.log(windowEl.scrollTop()) } windowEl.on('scroll', handler);
Fiddle
Adaptation from another stackoverflow answer
Comments
Post a Comment