Created
March 10, 2016 11:34
-
-
Save atwong/2977f779406b0a327a1c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
}); | |
}], | |
}; | |
} | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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)).