Skip to content

Instantly share code, notes, and snippets.

@kshreve
Created February 20, 2015 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kshreve/60ca227b70f0cba666a5 to your computer and use it in GitHub Desktop.
Save kshreve/60ca227b70f0cba666a5 to your computer and use it in GitHub Desktop.
infinite-scroll.js
(function() {
'use strict';
angular.module('app').directive('infiniteScroll', ['$window', function(window) {
return {
restrict: 'A',
link: function(scope, element, attributes) {
angular.element(window).bind('scroll', function () {
var container = window.document.body;
if((window.innerHeight + window.scrollY) >= window.document.body.offsetHeight) {
scope.$apply(attributes.infiniteScroll);
}
});
// If you want to have the element have it's own scroll bar, set height and overflow:auto, use below.
/*var container = element[0];
element.bind('scroll', function() {
if (container.scrollTop + container.offsetHeight >= container.scrollHeight) {
scope.$apply(attributes.infiniteScroll);
}
});*/
}
};
}])
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment