滚动到 md-virtual-repeat 的顶部

Scroll to top of md-virtual-repeat

我正在尝试在 md-virtual-repeat-container 中添加一个 "scroll to top of page" 按钮。我目前正在使用 $anchorScroll。我已将散列设置为 table 头(我已尝试在重复容器的内部和外部设置散列)并且 md-virtual-repeat 设置为重复 tr。单击按钮时,table 仅向上滚动一项并停止,它不会一直滚动到顶部。有什么想法吗?

我认为这可能是因为浏览器认为它只需要向上滚动一个 td 就可以到达哈希值,因为那是 DOM 中显示的内容,但实际上它需要滚动更多。

提前致谢!

    <md-virtual-repeat-container flex>
     <table>
      <thead id='scrollHash'>
       <tr><th></th><tr>
      </thead>
      <tbody>
       <tr md-virtual-repeat='data in repeatData'>
        <td></td>
      </tbody>
     </table>
    </md-virtual-repeat-container>
    <md-button class='md-fab' ng-click'$scope.gotoTop()'>Top</md-button>

您可以使用 md-top-index(阅读更多 here)。

试试这个:

在html中:

<md-virtual-repeat-container md-top-index="topIndex">...</md-virtual-repeat-container>
<md-button class='md-fab' ng-click="gotoTop()">Top</md-button>

在控制器中:

$scope.gotoTop = function()
{
    $scope.topIndex = 0;
}

代码here.

希望对您有所帮助。