Last active
November 21, 2018 12:05
-
-
Save jumbojett/5967535 to your computer and use it in GitHub Desktop.
AngularJS: Infinite Scrolling Directive
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
<div on-scroll="loadMore()"> | |
<!-- content --> | |
</div> |
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
/* | |
* Improved version of http://jsfiddle.net/vojtajina/U7Bz9/ | |
*/ | |
angular.module('scroll', []).directive('onScroll', function () { | |
return function (scope, elm, attr) { | |
angular.element(window).bind('scroll', function () { | |
if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) { | |
scope.$apply(attr.onScroll); | |
} | |
}); | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
I have been using the "old" code for infinity scroll and now I found your improvments. The old code was buggy and it failed few times. But with your code I didn't liked that it loaded all data after few scrolls. I modified the code a bit and I think this works better then old version, but loads data more slowly. Maybe this snippet will have somebody.
Best regards, Rok.