I have html like this for slides
幻灯片我有这样的HTML
<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
它在移动设备上工作。问题是当我在Firefox中拖动幻灯片2时(也在chrome中),幻灯片1也被拖动了。不能单独拖动幻灯片2。如何在浏览器中使用离子2中的2个完全独立的滑块
2 个解决方案
#1
6
Update Thanks to @cookiecookson from Slack channel:
更新感谢来自Slack频道的@cookiecookson:
- link to the github issue
- link to a PR that fixes this issue (not yet merged as of 27/06/2017)
链接到github问题
链接到解决此问题的公关(截至2017年6月27日尚未合并)
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.
似乎这是Ionic实施Swiper包装器时的一个错误。解决这个问题的一种方法是使用Swiper库的另一个包装器,就像这个一样。你可以在这个github仓库中找到一个演示应用程序。
The end result will be something like this:
最终结果将是这样的:
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)
然后将其导入app.module.ts文件(或您想要的模块中)
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>
#2
1
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>`;
};
}
}
#1
6
Update Thanks to @cookiecookson from Slack channel:
更新感谢来自Slack频道的@cookiecookson:
- link to the github issue
- link to a PR that fixes this issue (not yet merged as of 27/06/2017)
链接到github问题
链接到解决此问题的公关(截至2017年6月27日尚未合并)
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.
似乎这是Ionic实施Swiper包装器时的一个错误。解决这个问题的一种方法是使用Swiper库的另一个包装器,就像这个一样。你可以在这个github仓库中找到一个演示应用程序。
The end result will be something like this:
最终结果将是这样的:
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)
然后将其导入app.module.ts文件(或您想要的模块中)
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>
#2
1
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>`;
};
}
}