Skip to content

Instantly share code, notes, and snippets.

@atwong
Created March 10, 2016 11:34
Show Gist options
  • Save atwong/2977f779406b0a327a1c to your computer and use it in GitHub Desktop.
Save atwong/2977f779406b0a327a1c to your computer and use it in GitHub Desktop.
angular.module('aw.scroll-end', []).
directive('awscrollend', [function() {
return {
controller: ['$scope', '$element', function($scope, $element) {
$element.scroll(function(){
var scrollHeight = $element.prop("scrollHeight");
var clientHeight = $element.prop("clientHeight");
var remainder = scrollHeight - $element.scrollTop();
if (remainder == clientHeight) {
$scope.$emit('scrollend', $element);
}
});
}],
};
}
]);
@atwong
Copy link
Author

atwong commented Mar 10, 2016

Simple AngularJS directive to generate an event on reaching the bottom of an scrollable element. Useful for implementing infinite-scrolling and pagination. Simply add this directive to any scrollable element (i.e. overflow-y: (auto|scroll)).

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