【发布时间】:2020-01-13 17:49:04
【问题描述】:
有五个离子段按钮,
某事 |东西|东西|东西|东西
如果我单击第 4 段,则视图没有跟随或聚焦到当前段。
以上是当前截图
我希望在单击该段时将视图移动(向右或将其聚焦到中心)
HTML:
<ion-row>
<!-- ion-segment -->
<ion-toolbar>
<ion-segment (ionChange)="segmentChanged()" [(ngModel)]="segment" color="tertiary" scrollable>
<ion-segment-button value="0">
Something
</ion-segment-button>
<ion-segment-button value="1">
Something
</ion-segment-button>
<ion-segment-button value="2">
Something
</ion-segment-button>
<ion-segment-button value="3">
Something
</ion-segment-button>
<ion-segment-button value="4">
Something
</ion-segment-button>
</ion-segment>
</ion-toolbar>
<ion-col>
<ion-slides #slides (ionSlideDidChange)="slideChanged()" scrollbar="true" [options]="slideOpts">
<!-- Something -->
<ion-slide style="overflow-y: auto">
<p>Something</p>
</ion-slide>
<!-- Something -->
<ion-slide>
<p>Something</p>
</ion-slide>
<!-- Something -->
<ion-slide>
<p>Something</p>
</ion-slide>
<!-- Something -->
<ion-slide>
<p>Something</p>
</ion-slide>
<!-- Something -->
<ion-slide>
<p>Something</p>
</ion-slide>
</ion-slides>
</ion-col>
</ion-row>
TS:
slideOpts = {
zoom: false
};
@ViewChild('slides') slider: IonSlides;
segment = 0;
async segmentChanged() {
await this.slider.slideTo(this.segment);
}
async slideChanged() {
this.segment = await this.slider.getActiveIndex();
this.slider.update();
}
找到了其他解决方案,但它仅适用于 Ionic 3 或其他离子版本.. 非常感谢您的阅读
【问题讨论】:
标签: angular ionic-framework ionic4 ion-segment