I have html like this for slides
<ion-slides [pager]="false" slidesPerView="6" #slider_a>
<ion-slide *ngFor="let slide of items_a " #ddd>
<ion-card class="list-card" >
<div class="cardInnerWrap">
<ion-item>
{{slide.gameTitle}}
</ion-item>
<img src="{{slide.gameImage}}">
</div>
</ion-card>
</ion-slide>
</ion-slides>
<ion-slides [pager]="false" slidesPerView="6" #slider_b>
<ion-slide *ngFor="let slide of items_b " #ddd>
<ion-card class="list-card" >
<div class="cardInnerWrap">
<ion-item>
{{slide.gameTitle}}
</ion-item>
<img src="{{slide.gameImage}}">
</div>
</ion-card>
</ion-slide>
</ion-slides>
its working in mobile device. problem is when i drag slide 2 in Firefox(also in chrome) , slide 1 also getting dragged. cant drag slide 2 alone. How can i make 2 completely independent slider in ionic 2 that work in browser
Update Thanks to @cookiecookson from Slack channel:
Seems like it's a bug in Ionic's implementation of the Swiper wrapper. One way to solve it would be to use another wrapper for the Swiper library, just like this one. You can find a demo app in this github repo.
The end result will be something like this:
t
First you'd need to install it
npm install angular2-swiper --save
Then import it in the app.module.ts
file (or in the module you want)
import { KSSwiperModule } from 'angular2-swiper';
// ...
@NgModule({
declarations: [...],
imports: [KSSwiperModule, ...],
bootstrap: [...],
entryComponents: [..],
providers: [...]
})
export class AppModule { }
And then just use it in your page.
Component code:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
public items_a: Array<any>;
public items_b: Array<any>;
public options: any;
constructor(public navCtrl: NavController) {
this.items_a = [
{ gameTitle: 'Title1', gameImage: 'http://via.placeholder.com/200x200' },
{ gameTitle: 'Title2', gameImage: 'http://via.placeholder.com/200x200' },
{ gameTitle: 'Title3', gameImage: 'http://via.placeholder.com/200x200' },
{ gameTitle: 'Title4', gameImage: 'http://via.placeholder.com/200x200' },
{ gameTitle: 'Title5', gameImage: 'http://via.placeholder.com/200x200' },
{ gameTitle: 'Title6', gameImage: 'http://via.placeholder.com/200x200' },
{ gameTitle: 'Title7', gameImage: 'http://via.placeholder.com/200x200' },
{ gameTitle: 'Title8', gameImage: 'http://via.placeholder.com/200x200' },
{ gameTitle: 'Title9', gameImage: 'http://via.placeholder.com/200x200' }
];
this.items_b = [
{ gameTitle: 'Title10', gameImage: 'http://via.placeholder.com/200x200' },
{ gameTitle: 'Title11', gameImage: 'http://via.placeholder.com/200x200' },
{ gameTitle: 'Title12', gameImage: 'http://via.placeholder.com/200x200' },
{ gameTitle: 'Title13', gameImage: 'http://via.placeholder.com/200x200' },
{ gameTitle: 'Title14', gameImage: 'http://via.placeholder.com/200x200' },
{ gameTitle: 'Title15', gameImage: 'http://via.placeholder.com/200x200' },
{ gameTitle: 'Title16', gameImage: 'http://via.placeholder.com/200x200' },
{ gameTitle: 'Title17', gameImage: 'http://via.placeholder.com/200x200' },
{ gameTitle: 'Title18', gameImage: 'http://via.placeholder.com/200x200' }
];
this.options = {
slidesPerView: 3
}
}
}
View:
<ion-header>
<ion-navbar>
<ion-title>
Multiple slides
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<ks-swiper-container [options]="options">
<ks-swiper-slide *ngFor="let slide of items_a">
<ion-card class="list-card">
<div class="cardInnerWrap">
<ion-item>
{{ slide.gameTitle }}
</ion-item>
<img src="{{ slide.gameImage }}">
</div>
</ion-card>
</ks-swiper-slide>
</ks-swiper-container>
<ks-swiper-container [options]="options">
<ks-swiper-slide *ngFor="let slide of items_b">
<ion-card class="list-card">
<div class="cardInnerWrap">
<ion-item>
{{ slide.gameTitle }}
</ion-item>
<img src="{{ slide.gameImage }}">
</div>
</ion-card>
</ks-swiper-slide>
</ks-swiper-container>
</ion-content>
I found working solution here
HTML:
<ion-header no-border>
<ion-navbar transparent>
<ion-title>Custom Pagination</ion-title>
</ion-navbar>
</ion-header>
<ion-content text-center>
<h3>Pagination numbers</h3>
<ion-slides #sliderOne pager (ionDidChange)="onSlideChanged()">
<ion-slide *ngFor="let slide of slides"
[ngStyle]="{'background' : 'url(' + slide.imageUrl + ')'}">
<h2>{{slide.title}}</h2>
</ion-slide>
</ion-slides>
<h3>Pagination numbers 2</h3>
<ion-slides #sliderTwo pager (ionDidChange)="onSlideChanged()">
<ion-slide *ngFor="let slide of slides"
[ngStyle]="{'background' : 'url(' + slide.imageUrl + ')'}">
<h2>{{slide.title}}</h2>
</ion-slide>
</ion-slides>
<h3>Pagination icons</h3>
<ion-slides #sliderThree pager (ionDidChange)="onSlideChanged()">
<ion-slide *ngFor="let slide of slides"
[ngStyle]="{'background' : 'url(' + slide.imageUrl + ')'}">
<h2>{{slide.title}}</h2>
</ion-slide>
</ion-slides>
</ion-content>
TS:
import { Component, ViewChild } from '@angular/core';
import { NavController, Slides, IonicPage } from 'ionic-angular';
@IonicPage()
@Component({
selector: 'page-slide-custom-pagination',
templateUrl: 'slide-custom-pagination.html'
})
export class SlideCustomPaginationPage {
@ViewChild('sliderOne') sliderOne: Slides;
@ViewChild('sliderTwo') sliderTwo: Slides;
@ViewChild('sliderThree') sliderThree: Slides;
slides = [
{
title: 'Dream\'s Adventure',
imageUrl: 'assets/img/lists/wishlist-1.jpg',
songs: 2,
private: false
},
{
title: 'For the Weekend',
imageUrl: 'assets/img/lists/wishlist-2.jpg',
songs: 4,
private: false
},
{
title: 'Family Time',
imageUrl: 'assets/img/lists/wishlist-3.jpg',
songs: 5,
private: true
},
{
title: 'My Trip',
imageUrl: 'assets/img/lists/wishlist-4.jpg',
songs: 12,
private: true
}
];
constructor(public navCtrl: NavController) { }
ngAfterViewInit() {
this.sliderOne.paginationBulletRender = (index, className) => {
return `<span class="custom-pagination ${className}>${index + 1}</\span>`;
};
this.sliderTwo.paginationBulletRender = (index, className) => {
return `<span class="custom-pagination-2 ${className}>${index + 1}</\span>`;
};
this.sliderThree.paginationBulletRender = (index, className) => {
return `<span class="custom-pagination-3 bullet-icon-${index + 1} ${className}></\span>`;
};
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With