尝试设置id
我认为这不是正确的方式。
Freaky Jolly 有一个教程解释如何滚动到 X/Y 坐标 https://www.freakyjolly.com/ionic-4-how-to-scroll-to-top-bottom-using-ion-content-scroll-events/.
首先,你需要scrollEvents
on the ion-content
:
<ion-header>
<ion-toolbar>
<ion-title>
Ion Content Scroll
</ion-title>
</ion-toolbar>
</ion-header>
<ion-content [scrollEvents]="true">
<div style="height: 50px;width:600px;" text-right>
<ion-button (click)="ScrollToPoint(-300, -120)">
Scroll To Point Right
</ion-button>
</div>
</ion-content>
在代码中您需要使用@ViewChild
获取代码参考ion-content
那么你可以使用它的ScrollToPoint()
api:
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) content: IonContent;
constructor(
){
}
ScrollToPoint(X,Y){
this.content.scrollToPoint(X,Y,1500);
}
}
我已经简化了这篇文章,因此如果您希望它真正起作用,您需要在其中添加一些内容来向页面添加滚动条。