gpt4 book ai didi

javascript - 无限滚动导致快速滚动时跳转到屏幕顶部

转载 作者:行者123 更新时间:2023-11-30 17:04:04 25 4
gpt4 key购买 nike

我正在使用 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>

Controller 代码:

$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;
});
}

最佳答案

要非常小心你的样式表...我在 DOM 上有一个 css 类来防止显示没有加载图片的项目,这个 css 类在图像加载后被删除。然而,ng-infinite-scroll 将 ng-repeat DOM 替换为原始默认 HTML 模板(和 CSS 类!),因此在一瞬间,css 类导致项目的高度基本上为零。这当然迫使我进入页面顶部。

关于javascript - 无限滚动导致快速滚动时跳转到屏幕顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28334409/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com