Mat*_*nis 1 javascript infinite-scroll angularjs nginfinitescroll
我在我的网站上使用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>
Run Code Online (Sandbox Code Playgroud)
控制器代码:
$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;
});
}
Run Code Online (Sandbox Code Playgroud)
非常小心你的样式表......我在 DOM 上有一个 css 类来防止显示没有加载图片的项目,加载图像后删除了这个 css 类。然而 ng-infinite-scroll 用原始的默认 HTML 模板(和 CSS 类!)替换了 ng-repeat DOM,因此一瞬间,css 类导致项目的高度基本上为零。这当然迫使我到页面的顶部。
| 归档时间: |
|
| 查看次数: |
1834 次 |
| 最近记录: |