【问题标题】:anchorScroll not working, going to top of pageanchorScroll 不工作,转到页面顶部
【发布时间】:2015-08-25 15:43:54
【问题描述】:

我有以下代码

$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>

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

【问题讨论】:

  • 你找到解决这个问题的方法了吗?

标签: angularjs anchor-scroll


【解决方案1】:

您的ng-repeatid 分配给父元素(在本例中为races div),您可能需要先对其进行修改:

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

【讨论】:

  • 我也试过你的代码。但它把我带到了页面的顶部。任何 html 或我需要明确接受的任何内容??
猜你喜欢
  • 2012-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多