【问题标题】:Ionic 3 - ion-slides not working on browserIonic 3 - 离子幻灯片在浏览器上不起作用
【发布时间】:2017-11-20 01:40:44
【问题描述】:

在 ionic 3 中,我使用的是 ion-slides;在 Android 和 iOS 应用上一切正常:我可以滑动每一行,而其他行保持不动。

在尝试使用鼠标“滑动”的浏览器上,没有任何效果;如果我滑动第一行,第二行和第三行的幻灯片也会改变位置。

这是我的模板:

<ion-card *ngFor="let channel of channels; let i = index;">
        <ion-card-header {{channel.title}}</ion-card-header>
        <ion-card-content>
            <ion-slides slidesPerView=4 spaceBetween="5">
                <ion-slide *ngFor="let video of channels[i].playlist">
                    <img src="https://.../thumbs/{{video.mediaid}}"/>
                </ion-slide>
            </ion-slides>
     </ion-card-content>
 </ion-card>

我错过了什么?

我也尝试使用下一个和上一个按钮,但我找不到传递滑动选项的方法(从 Ionic 3.0.0 中删除了幻灯片输入选项)。

我应该如何初始化滑块?

在 Swiper 中我应该设置:

{ ...,
nextButton: '.swiper-button-next',
prevButton: '.swiper-button-prev',
...
}

【问题讨论】:

  • 如果您使用浏览器作为移动设备进行检查(例如 iphone 4)并点击重新加载,它是否按预期工作?
  • 是的,效果很好

标签: angular typescript ionic-framework


【解决方案1】:

检查Slide documentation,它有你需要的一切。

例如,您可以有一个按钮来转到下一张幻灯片,如下所示:

<button ion-button (click)="goToNextSlide()">Next</button>
import { QueryList, ViewChildren } from '@angular/core';
import { Slides } from 'ionic-angular';

class MyPage {
  @ViewChildren(Slides) slides: QueryList<Slides>;

  goToNextSlide() {
    this.slides.forEach((slide) => { slide.next(); });
  }
}

【讨论】:

  • 我有多个幻灯片行。当我单击按钮时(如您的回答),只有第一行中的幻灯片继续移动。可能我应该拥有与幻灯片行一样多的 @ViewChild 实例;但我不知道该怎么做
  • 您的问题并不清楚您有多行。然后只需使用 @ViewChildren 代替。检查我上面更新的代码。
  • 非常感谢您的提示。为了避免所有幻灯片一起移动,我发现了这种方式:nextSlide(i) { this.slides.forEach((slides, index) =&gt; { if (index == i) { slides.slideNext(); } }) } 有没有更好的方法来获得相同的结果?
  • 酷。干得好!
猜你喜欢
  • 2018-03-07
  • 2020-09-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-09
  • 2019-02-05
  • 1970-01-01
  • 2021-05-06
相关资源
最近更新 更多