Skip to content

Instantly share code, notes, and snippets.

@troggy
Created October 27, 2014 05:41
Show Gist options
  • Save troggy/5e563731f974730f74f3 to your computer and use it in GitHub Desktop.
Save troggy/5e563731f974730f74f3 to your computer and use it in GitHub Desktop.
Angular scrollTop directive
angular.module('webApp')
.directive('tnScrollTop', ['$window', function($window){
return {
restrict: 'A',
link: function(scope, elem, attr, ctrl) {
var windowEl = angular.element($window);
var handler = function() {
scope.scrollTop = windowEl.scrollTop();
};
windowEl.on('scroll', scope.$apply.bind(scope, handler));
handler();
}
};
}]);
@lucaszhu2zgf
Copy link

have you ever test the code?
angular.js:13424 TypeError: angular.element(...).scrollTop is not a function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment