ionic 3 image slider stops autoplay after manual sliding

前端 未结 3 457
时光取名叫无心
时光取名叫无心 2021-01-17 15:20

Ionic 3 image slider autoplay works well, but when I slide the image manually the autoplay stops working. Below is my ionic 3 code. I am really stuck here..

         


        
相关标签:
3条回答
  • 2021-01-17 16:03

    If someone finds a solution for Ionic 4, to restart the slider after manual sliding just define like this:

    slideOptsOne = {
        initialSlide: 0,
        slidesPerView: 1,
        autoplay: {
          disableOnInteraction: false
        }
      };
    

    HTML:

    <ion-slides [options]="slideOptsOne" color="tertiary">
    

    Reference: https://swiperjs.com/api/#autoplay Cheers

    0 讨论(0)
  • 2021-01-17 16:05

    I used the following code and it is working fine and as expected:

    // in your .ts file

    slideOptsOne = {
        initialSlide: 0,
        slidesPerView: 1,
        autoplay: {
          delay: 3000,
          disableOnInteraction: false
        }
    
      };
    

    And in your HTML -

    <ion-slides pager="false" [options]="slideOptsOne">
    

    Note: I am NOT even referencing the slider in my .ts file and calling autoplay on slidesDidLoad event as follows:

    slidesDidLoad(slides: IonSlides) {
       slides.startAutoplay();
    }
    
    0 讨论(0)
  • 2021-01-17 16:11

    Update:

    You need to use it like this:

    import { Component, ViewChild } from '@angular/core';
    import { IonicPage, NavController, NavParams, Slides } from 'ionic-angular';
    
    @ViewChild(Slides) slides: Slides;
    
    constructor(private navCtrl: NavController, private navParams: NavParams) {
      }
    
      ionViewDidEnter() {
        this.slides.autoplayDisableOnInteraction = false;
      }
    

    Note: You need to remove autoplayDisableOnInteraction = "false" on html page.

    Old Answer:

    You can use autoplayDisableOnInteraction = "false" as shown below.

        <ion-slides  class="slide-css" autoplay="100" loop="true" speed="100" 
                     pager="true" autoplayDisableOnInteraction = "false">
    
        </ion-slides>
    

    See how it implements on Ionic

    Swiper API

    disableOnInteraction boolean true Set to false and autoplay will not be disabled after user interactions (swipes), it will be restarted every time after interaction

    0 讨论(0)
提交回复
热议问题