我在AngularJS + Node.js应用程序上实现了无限滚动功能.
它基于这个JSfiddle并以相同的方式工作:http://jsfiddle.net/vojtajina/U7Bz9/ HTML:
<div id="fixed" when-scrolled="loadMore()">
<ul>
<li ng-repeat="i in items">{{i.id}}</li>
</ul>
</div>?
Run Code Online (Sandbox Code Playgroud)
使用Javascript:
function Main($scope) {
$scope.items = [];
var counter = 0;
$scope.loadMore = function() {
for (var i = 0; i < 5; i++) {
$scope.items.push({id: counter});
counter += 10;
}
};
$scope.loadMore();
}
angular.module('scroll', []).directive('whenScrolled', function() {
return function(scope, elm, attr) {
var raw = elm[0];
elm.bind('scroll', function() {
if (raw.scrollTop + raw.offsetHeight >= raw.scrollHeight) {
scope.$apply(attr.whenScrolled);
}
});
};
}); …Run Code Online (Sandbox Code Playgroud)