vue-awesome-swiper icon indicating copy to clipboard operation
vue-awesome-swiper copied to clipboard

[Bug] Swiper is not looping correctly

Open AndrewBogdanovTSS opened this issue 6 years ago • 23 comments

Vue.js version and component version

2.5.17

Nuxt version

2.0.0-25550715.56db988

Reproduction Link

https://github.com/AndrewBogdanovTSS/nuxt2-awesome-swiper

Steps to reproduce

  • Specify swiper options as stated below
  • Set div.swiper-slide style width to auto to wrap to a size of the provided image

Swiper settings config object

swiperOptions: {
                    pagination: {
                        el: '.swiper-pagination',
                        clickable: true
                    },
                    navigation: {
                        nextEl: '.swiper-button-next',
                        prevEl: '.swiper-button-prev'
                    },
                    loop: true,
                    slidesPerView: 'auto',
                    loopedSlides: 10
                }

What is Expected?

Swiper is looping indefinitely in both directions

What is actually happening?

Swiper is looping indefinitely only backwards

AndrewBogdanovTSS avatar Sep 17 '18 15:09 AndrewBogdanovTSS

@AndrewBogdanovTSS the same problem but my settings looks like this

swiperOption: {
                    loop: true,
                    slidesPerView: 1
}

and looping does not working in both direction

vasiliysmirnov avatar Sep 22 '18 21:09 vasiliysmirnov

I have this problem too. My options:

        autoplay: { delay: 5000 },
        keyboard: { enabled: true },
        loop: true,
        navigation: {
          nextEl: '.swiper-button-next',
          prevEl: '.swiper-button-prev'
        },
        pagination: {
          el: '.swiper-pagination',
          clickable: true,
          renderBullet: (idx, className) =>
            `<a href="#" class="${className}">${idx + 1}</a>`
        },
        slidesPerView: 1,
        spaceBetween: 16

dw72 avatar Jan 13 '19 17:01 dw72

Ok for me this reolved the problem: https://github.com/surmon-china/vue-awesome-swiper/issues/322#issuecomment-383888576

dw72 avatar Jan 13 '19 18:01 dw72

@dw72 didn't help in my case

AndrewBogdanovTSS avatar Apr 06 '19 08:04 AndrewBogdanovTSS

these settings worked for me :+1:

      swiperOption: {
	slidesPerView: 1,
	autoplay: { delay: 2000 },
         spaceBetween: 30,
        loop: true,
        navigation: {
          nextEl: ".swiper-button-next",
          prevEl: ".swiper-button-prev"
        }
      }

It seems that by adding autoplay the slider works as expected.

achimoraites avatar May 07 '19 11:05 achimoraites

@Cyb3rN4u7 but what if I don't want autoplay behavior?

AndrewBogdanovTSS avatar May 07 '19 11:05 AndrewBogdanovTSS

@AndrewBogdanovTSS you tried set autoplay: flase or call mySwiper.autoplay.stop();?

dw72 avatar May 07 '19 12:05 dw72

@AndrewBogdanovTSS what version do you currently use ? My version is "vue-awesome-swiper": "^3.1.3"

achimoraites avatar May 07 '19 12:05 achimoraites

Ok for me this reolved the problem: #322 (comment)

Thank for this solution

ptucky avatar Jun 23 '19 15:06 ptucky

The swiper slides fine but on the first slide the animation just doesn't work at all. This only happens when loop is set to true which I NEED.

Settings:

swiperOption: {
        loop: true,
        effect: 'coverflow',
        grabCursor: false,
        slidesPerView:'auto',
        centeredSlides: true,
        coverflowEffect: {
            rotate: 0,
            stretch: 0,
            depth: 400,
            modifier: 1,
            slideShadows : false,
        }, 
        autoplay: {
            delay: 1000,
            disableOnInteraction: false,
        },
}

StijnKlarenbeek avatar Jul 20 '19 11:07 StijnKlarenbeek

La configuración más completa para el swiper tipo effect coverflow

swiperOption: {
      centeredSlides: true,
      effect: 'coverflow',
      grabCursor: true,
      loop: true,
      slidesPerView: 2,
      autoplay: {
	delay: 2500,
	disableOnInteraction: false
      },
      coverflowEffect: {
        rotate: 50,
        stretch: 0,
        depth: 100,
        modifier: 1,
        slideShadows : true
      },
      pagination: {
        el: '.swiper-pagination',
        clickable: true
      }
    }

Victor116 avatar Mar 09 '20 23:03 Victor116

Could someone investigate the origin of an issue instead of pasting random configs that "works"?

AndrewBogdanovTSS avatar Mar 10 '20 07:03 AndrewBogdanovTSS

I'll be referencing this issue https://github.com/surmon-china/vue-awesome-swiper/issues/322#issuecomment-383888576 as it solved my problem using this config:

 swiperOptions: {
      init: true,
      slidesPerView: 'auto',
      centeredSlides: true,
      loop: true,
      loopedSlides: 0,
      slidesPerGroup: 1,
      spaceBetween: 30
    }

basically only render the swiper once you have data (slides)

MrToxy avatar Jun 17 '20 17:06 MrToxy

For me I was using it with dynamic data, and even after the data is ready, before initialization, the loop wasn't working

setTimeout(() => {
    this.initHeroSwiper();
}, 400);

had to wait so the component get rendered, and that solved my issue

abdessamadely avatar Aug 02 '20 10:08 abdessamadely

this.initHeroSwiper()

Please, what is inside in this function of yours?

Thanks

labs20 avatar Oct 15 '20 14:10 labs20

initHeroSwiper() {
    let height = window.innerWidth * 0.42207;
    if (height > 650) height = 650;
    this.$refs.heroSwiperContainer.style.height = `${height}px`;

    let mySwiper = new Swiper('.hero-swiper-container', {
        loop: true,
        autoplay: true,
        roundLengths: true,
    });

    mySwiper.on('resize', e => {
        let height = e.width * 0.42207;
        if (height > 650) height = 650;
        this.$refs.heroSwiperContainer.style.height = height;
    });
},

abdessamadely avatar Oct 15 '20 15:10 abdessamadely

Added this to the swiperOptions and it is working.

slidesPerGroup: 1

mateomm22 avatar Aug 09 '21 20:08 mateomm22

I have this problem too! If I slide to the left, everything seems fine, but when I swipe to the right, the loop doesn`t work. I think the issue reproducible when width of all the slides (not cloned) less than width of "viewport".

AvdeevaEvgeniya avatar Oct 22 '21 21:10 AvdeevaEvgeniya

"centeredSlides: true" - it helped me, but the thing is, I don't need to center the slides.

AvdeevaEvgeniya avatar Oct 22 '21 21:10 AvdeevaEvgeniya

@AvdeevaEvgeniya fix this problem like a god, thanks <3

ThiGaleno avatar Sep 01 '22 14:09 ThiGaleno

I have this problem too! If I slide to the left, everything seems fine, but when I swipe to the right, the loop doesn`t work. I think the issue reproducible when width of all the slides (not cloned) less than width of "viewport".

I confirm that the problem manifests itself in the specified conditions

StPalatinus avatar Oct 29 '22 18:10 StPalatinus

Still same problem here

FlambeSk avatar Mar 10 '23 19:03 FlambeSk

Looks like it easier to create new slider from cratch, than find out the solution for swiper.

Enkratia avatar Mar 31 '23 18:03 Enkratia