Skip to content

Instantly share code, notes, and snippets.

@sp90
Last active June 12, 2018 08:11
Show Gist options
  • Save sp90/9d1ee0956c1a56567e429b446d6b0b4b to your computer and use it in GitHub Desktop.
Save sp90/9d1ee0956c1a56567e429b446d6b0b4b to your computer and use it in GitHub Desktop.
Simplest infinite scroll module (194 bytes GZIPPED)
(function() {
'use strict';
var modules = [];
angular
.module('directive.whenScrolled', modules)
.directive('whenScrolled', whenScrolled);
function whenScrolled() {
return {
restrict: 'A',
link: function(scope, elem, attrs) {
// we get a list of elements of size 1 and need the first element
var raw = elem[0];
// we load more elements when scrolled past a limit
elem.bind('scroll', function() {
if (raw.scrollTop + raw.offsetHeight + 5 >= raw.scrollHeight) {
scope.loading = true;
// we can give any function which loads more elements into the list
scope.$apply(attrs.whenScrolled);
}
});
}
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment