Created
February 20, 2015 18:18
-
-
Save kshreve/60ca227b70f0cba666a5 to your computer and use it in GitHub Desktop.
infinite-scroll.js
This file contains 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
(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