2015-08-25 25 views
1

顶部我有下面的代码anchorScroll不工作,去

$scope.scrollTo = function(id) { 
    alog($location.hash()); 
    var toScrollId = "anchor" + id; 
    if($location.hash() !== toScrollId){ 
     alog(" hash is not equal") 
     $location.hash(toScrollId); 
    }else{ 
     alog(" hash is equal") 
     $anchorScroll(); 
    } 
}; 

和HTML看起来像

<button ng-click="scrollTo(raceid)">GO TO THIS</button> 

<div ng-repeat="race in races" id="{{ 'anchor' + race.raceId}}"> 
</div> 

但滚动总是转到页的顶部。我做错了什么?

+0

你找到任何解决这个问题? – WASIF

回答

1

ng-repeat被分配id父元素(在这种情况下,races格),你可能需要修改,首先:

<div ng-repeat="race in races" id="races"> 
    <div id="{{ 'anchor' + race.raceId }}">Some race</div> 
</div> 
+0

我也试过我们的代码。但它把我带到页面顶部。任何HTML或任何我需要明确?? – Hacker