我试图在主页之后开始每页大约500px,类似于这个网站:http://unionstationdenver.com/
您会注意到在主页后查看页面时,您会自动向下滚动而不另行通知,但您可以向上滚动以再次调整特色滑块.
我玩过scrolledHeight,但我不认为这就是我需要的????
基本上我有一个特色部分位于我的所有内容页面之上,但在向上滚动之前,您不应该看到此部分.有帮助吗?
我尝试从解决方案到此工作
如何在AngularJS中保留ng-repeat的滚动位置?
在删除ng-repeat中的顶部项目时实现保留滚动位置但无法找出执行此操作的代码.
另外,请注意,列表应按与items数组相同的顺序打印,而不是像示例那样反向打印.
解决方案的代码:
angular.module("Demo", [])
.controller("DemoCtrl", function($scope) {
$scope.items = [];
for (var i = 0; i < 10; i++) {
$scope.items[i] = {
id: i,
name: 'item ' + i
};
}
$scope.addNewItem = function() {
$scope.items = $scope.items.concat({
id: $scope.items.length,
name: "item " + $scope.items.length
});
};
})
.directive("keepScroll", function(){
return {
controller : function($scope){
var element = 0;
this.setElement = function(el){
element = el;
}
this.addItem = function(item){
console.log("Adding item", item, item.clientHeight);
element.scrollTop = (element.scrollTop+item.clientHeight+1); …Run Code Online (Sandbox Code Playgroud)