Skip to content

Instantly share code, notes, and snippets.

@NicolaasZA
Forked from mdorchain/sliding-segments.page.html
Last active June 15, 2021 11:56
Show Gist options
  • Save NicolaasZA/0b7249f02456b5d2d5f281c599ef402b to your computer and use it in GitHub Desktop.
Save NicolaasZA/0b7249f02456b5d2d5f281c599ef402b to your computer and use it in GitHub Desktop.
Ionic 5 Sliding segments
<ion-header>
<ion-toolbar>
<ion-title>
Sliding Segments
</ion-title>
</ion-toolbar>
</ion-header>
<ion-content class="ion-padding">
<ion-toolbar>
<ion-segment (ionChange)="segmentChanged()" [(ngModel)]="segment" color="warning">
<ion-segment-button value="0">
<ion-icon name="person"></ion-icon>
</ion-segment-button>
<ion-segment-button value="1">
<ion-icon name="camera"></ion-icon>
</ion-segment-button>
<ion-segment-button value="2">
<ion-icon name="newspaper"></ion-icon>
</ion-segment-button>
</ion-segment>
</ion-toolbar>
<ion-slides (ionSlideDidChange)="slideChanged()" scrollbar="true">
<ion-slide>
First
</ion-slide>
<ion-slide>
second
</ion-slide>
<ion-slide>
third
</ion-slide>
</ion-slides>
</ion-content>
ion-slide {
height: calc(100vh - 140px);
}
import { Component, OnInit, ViewChild } from '@angular/core';
import { IonSlides } from '@ionic/angular';
@Component({
selector: 'app-demo',
templateUrl: './demo.page.html',
styleUrls: ['./demo.page.scss'],
})
export class DemoPage implements OnInit {
@ViewChild(IonSlides, { static: true }) slider: IonSlides;
segment = 0;
constructor(
) { }
ngOnInit() {
}
async segmentChanged() {
await this.slider.slideTo(this.segment);
}
async slideChanged() {
this.segment = await this.slider.getActiveIndex();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment