我正在使用AngularJS构建一个应用程序,由于需要展示大量的物品,因此我已经实现了无限滚动技术,这比分页更好。但不好的一点是,如果用户点击某个物品进入其详细页面,当用户返回时,将回到顶部,需要重新向下滚动。我的目标是,当用户点击“后退”按钮时,可以回到他之前浏览的位置!
展示物品:
那是控制器。
展示物品:
<div class="container" id="infinit-container" ng-controller="ArticlesController">
<div id="fixed" when-scrolled="LoadMore()">
<div ng-repeat="article in Articles">
<article-post article="article"></article-post>
</div>
</div>
</div>
这里是when-scrolled指令
app.directive('whenScrolled', function () {
return function (scope, element, attrs) {
$('#fixed').height($(window).height());
var div = element[0];
element.bind('scroll', function () {
if (div.scrollTop + div.offsetHeight >= div.scrollHeight) {
scope.$apply(attrs.whenScrolled);
}
})
}
})
那是控制器。
app.controller('ArticlesController', function ($scope, UserService) {
$scope.Articles = [];
var page = 0;
$scope.LoadMore = function () {
UserService.Articles(page)
.success(function (data) {
$scope.Articles.push.apply($scope.Articles, data);
});
page++;
};
$scope.LoadMore();
});