我想滚动到页面顶部,因为我的列表包含一长串数据,我该怎么做?
I want to scroll to the top of the page as my list contains a long list of data, how do i do this?
我一直在浏览涵盖相同问题的文章,但其中大部分是使用 javascript 完成的。我想在 Angular 4 和 ironic 3.
中完成这个
非常感谢您的帮助。
对于 Ionic 2 及更高版本,对内容 class 使用 scrollToTop()
方法。
page.html
<ion-content>
Add your content here!
</ion-content>
page.ts
import { Component, ViewChild } from '@angular/core';
import { Content } from 'ionic-angular';
@Component({...})
export class MyPage{
@ViewChild(Content) content: Content;
scrollToTop() {
this.content.scrollToTop(400);
}
}
或者您可以随时调用 scrollTop()。
注意:400 是以毫秒为单位的持续时间,它是可选的,你也可以使用它
this.content.scrollToTop();
在这种情况下,scrollToTop() 将设置默认值 300。
我一直在浏览涵盖相同问题的文章,但其中大部分是使用 javascript 完成的。我想在 Angular 4 和 ironic 3.
中完成这个非常感谢您的帮助。
对于 Ionic 2 及更高版本,对内容 class 使用 scrollToTop()
方法。
page.html
<ion-content>
Add your content here!
</ion-content>
page.ts
import { Component, ViewChild } from '@angular/core';
import { Content } from 'ionic-angular';
@Component({...})
export class MyPage{
@ViewChild(Content) content: Content;
scrollToTop() {
this.content.scrollToTop(400);
}
}
或者您可以随时调用 scrollTop()。 注意:400 是以毫秒为单位的持续时间,它是可选的,你也可以使用它
this.content.scrollToTop();
在这种情况下,scrollToTop() 将设置默认值 300。