AngularJs使用$ anchorScroll滚动

时间:2015-11-02 16:16:03

标签: angularjs scroll

如果您单击一个段落,我正在尝试使用$ anchorScroll滚动到ID。出于某种原因,只有在您点击两次段落时它才有效。

查看:

<div class="col-xs-12">
<p ng-repeat="item in items" ng-click="gotoAnchor(item .visibleName)">    {{item .visibleName}}</p>
</div>

<div class="col-xs-12" ng-repeat="item in items" >
<div id="anchor{{item .visibleName}}">
    <h1>{{item.idPrimary}}</h1>
</div>

控制器:

$scope.gotoAnchor  = function(x) {
    var newHash = 'anchor' + x;
    if ($location.hash() != newHash) {
      $location.hash('anchor' + x);
    } else {
      $anchorScroll();
    }
  };

0 个答案:

没有答案