[英]How to Vertical ion-item Scroll to Bottom and Top on Down and Up arrow icon button click in ionic 4?
我正在创建Ionic 4 plus Angular App,我想添加向上和向下箭头按钮以垂直滚动从上到下,反之亦然。
You can use the Content component to handle scrolling in code. 您可以使用Content组件来处理代码滚动。 You can use
scrollToTop()
or scrollToBottom()
as well as scrollToPoint()
, whatever fits your need. 您可以根据需要使用
scrollToTop()
或scrollToBottom()
以及scrollToPoint()
。
For more info see https://ionicframework.com/docs/api/content#scrollToTop 有关更多信息,请参见https://ionicframework.com/docs/api/content#scrollToTop
import { Component, ViewChild } from '@angular/core';
import { Content } from 'ionic-angular';
@Component({...})
export class MyPage{
@ViewChild(Content) content: Content;
scrollToTop() {
this.content.scrollToTop();
}
}
check the ionic docs for info on component methods https://ionicframework.com/docs/api/content 检查ionic文档以获取有关组件方法的信息https://ionicframework.com/docs/api/content
.html html的
<ion-content>
<ion-icon name="arrow-dropdown" (click)="scrollToBottom()"></ion-icon>
//..... your content ......
<ion-icon name="arrow-dropup" (click)="scrollToTop()"></ion-icon>
</ion-content>
.ts .TS
import { Component, ViewChild } from '@angular/core';
import {IonContent} from '@ionic/angular';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
@ViewChild(IonContent) theContent: IonContent;
scrollToBottom(){
this.theContent.scrollToBottom();
}
scrollToTop(){
this.theContent.scrollToTop();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.