滚动到md-virtual-repeat的顶部

时间:2016-04-19 17:50:38

标签: angularjs angularjs-ng-repeat material-design ng-repeat angular-material

我正在尝试在md-virtual-repeat-container中添加“滚动到页面顶部”按钮。我目前正在使用$ anchorScroll。我已经将哈希设置为表头(我已经尝试在重复容器内部和外部设置哈希)并且md-virtual-repeat设置为重复tr。单击该按钮时,该表仅向上滚动一个项目并停止,它不会一直滚动到顶部。有什么想法吗?

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

提前谢谢!

interface CompilerOptions {
    allowNonTsExtensions?: boolean;
    charset?: string;
    codepage?: number;
    declaration?: boolean;
    diagnostics?: boolean;
    emitBOM?: boolean;
    help?: boolean;
    locale?: string;
    mapRoot?: string;                                 // Optionally Specifies the location where debugger should locate map files after deployment
    module?: string;                                  //'amd'|'commonjs' (default)
    noEmitOnError?: boolean;
    noErrorTruncation?: boolean;
    noImplicitAny?: boolean;                          // Error on inferred `any` type
    noLib?: boolean;
    noLibCheck?: boolean;
    noResolve?: boolean;
    out?: string;
    outDir?: string;                                  // Redirect output structure to this directory
    preserveConstEnums?: boolean;
    removeComments?: boolean;                         // Do not emit comments in output
    sourceMap?: boolean;                              // Generates SourceMaps (.map files)
    sourceRoot?: string;                              // Optionally specifies the location where debugger should locate TypeScript source files after deployment
    suppressImplicitAnyIndexErrors?: boolean;
    target?: string;                                  // 'es3'|'es5' (default)|'es6'
    version?: boolean;
    watch?: boolean;
}

1 个答案:

答案 0 :(得分:2)

您可以使用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

希望得到这个帮助。