我在我的网站上使用了ng-infinite-scroll Angular指令,它的整体效果很好。但是,在测试时,我注意到如果我快速滚动,页面会跳回顶端。以下是我的html和我的滚动功能。我认为问题在于$scope.busy
如何处理:无限滚动导致在快速滚动时跳转到屏幕顶部
HTML:
<div class="row inner" infinite-scroll="loadImages()" infinite-scroll-distance="1" infinite-scroll-disabled="busy">
<h2 class="headline">{{event}}</h2>
<h3 class="headline">{{city}}, {{state}}</h3>
<div class="col-md-3 col-sm-4 col-xs-12 img-container" ng-repeat="photo in photos">
<a ng-href="{{photo.link}}" target="_blank" title="{{photo.text}}"><img ng-src="{{photo.img}}" onerror="imgError(this);" alt="" class="img-responsive insta" id="image"></a>
<div class="prof-circ" title="{{photo.username}}"><a ng-href="http://instagram.com/{{photo.username}}" target="_blank"><img ng-src="{{photo.profile}}" onerror="anonImg(this);" alt="" class="circular"></a></div>
</div>
控制器代码:
$scope.loadImages = function() {
if ($scope.busy) return;
$scope.busy = true;
$scope.limit += 20;
Events.get($scope.id,$scope.limit).success(function(response) {
$scope.photos = response.photos.reverse();
$scope.busy = false;
});
}
如果您可以提供一个plnkr .co/jsfiddler演示,帮助调试会更容易。 – Rebornix