Swiper: Final 3 slides in loop do not fire `onClick` event initially

Created on 28 Jun 2017  Â·  7Comments  Â·  Source: nolimits4web/swiper

This is a (multiple allowed):

  • [x] bug
  • [ ] enhancement
  • [ ] feature-discussion (RFC)
  • Swiper Version: 3.4.2
  • Platform/Target and Browser Versions: 58.0.3029.110 (64-bit)

What you did

  1. I initiated with the following settings, lazy loaded loop
  2. I loaded the gallery
  3. I clicked previous button
  4. I clicked slide
initialSlide: 0,
slidesPerView: 6,
slidesPerGroup: 6,
breakpoints: {
  570: {slidesPerView: 1, slidesPerGroup: 1, lazyLoadingInPrevNextAmount: 1},
  1140: {slidesPerView: 2, slidesPerGroup: 2, lazyLoadingInPrevNextAmount: 2},
  1710: {slidesPerView: 3, slidesPerGroup: 3, lazyLoadingInPrevNextAmount: 3},
  2280: {slidesPerView: 4, slidesPerGroup: 4, lazyLoadingInPrevNextAmount: 4}
},
setWrapperSize: true,
pagination: '.swiper-pagination',
paginationClickable: true,
preloadImages: false,
lazyLoading: true,
lazyLoadingInPrevNext: true,
watchSlidesVisibility: true,
grabCursor: true,
loop: true,
nextButton: '.swiper-button-next',
prevButton: '.swiper-button-prev',
onClick: function(swiper) {
  console.log('I expect this to fire');
}

Expected Behavior

I expected the onClick action to happen.

Actual Behavior

No click event fired...

It is ONLY for the initial slide click on the previous (end of loop) slides. If I have 60 slides in total, starting at 0, and click BACK before clicking anything, the final 3 (58, 59, 60) will not trigger click event. Clicking BACK again (55, 56, 57) and clicking the slide triggers the event.

Most helpful comment

As I understand, this thing happens because after the initialization of swiper with 'loop: true', it adds 2 additional slides: before the first user's slide(just a copy of the last user's slide) and after the last one(copy of the first user's slide). This thing adds a possibility to slide from the 1 slide to the last one using touch and visual consistency.

But the problem here is that this copy of slide is just a simple DOM copy, without event listeners, etc. So until you make at least a small swipe, Swiper doesn't change active-slide class to the user's slide, where all event listeners are added and work properly.

All 7 comments

exactly the same issue! I'm not using lazy loading, my config is below:

    scrollbar: null,
    direction: 'horizontal',
    slidesPerView: 1,
    scrollbarHide: true,
    keyboardControl: true,
    mousewheelControl: true,
    pagination: null,
    nextButton: '.my-swiper-button-next',
    prevButton: '.my-swiper-button-prev',
    loop: true,
    preventClicks: false,
    preventClicksPropagation: false,

no clicking event in loop, after first slide to last slide.

The same here (not using lazy loading as well — v.3.4.2).
I have several slides, loop mode is set to 'true'. After the initial rendering when I switch to the previous(last) slide and try to click on my slide to trigger some event — no click events are fired.

The same behavior when switching from the last slide to the first one — after that no click events are triggered on lmc. But after some touch event will be triggered, slide begins to work properly with all events which are added to it.

yeah, I have the same problem. Now I have to set loop to false

As I understand, this thing happens because after the initialization of swiper with 'loop: true', it adds 2 additional slides: before the first user's slide(just a copy of the last user's slide) and after the last one(copy of the first user's slide). This thing adds a possibility to slide from the 1 slide to the last one using touch and visual consistency.

But the problem here is that this copy of slide is just a simple DOM copy, without event listeners, etc. So until you make at least a small swipe, Swiper doesn't change active-slide class to the user's slide, where all event listeners are added and work properly.

any solutions?

Issue is closed because of not actual anymore

If this issue is still actual and reproducible for latest version of Swiper, please create new issue and fill the issue template correctly:

  • Clearly describe the issue including steps to reproduce when it is a bug.
  • Make sure you fill in the earliest version that you know has the issue.
  • Provide live link or JSFiddle/Codepen or website with issue

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Hiralpandya picture Hiralpandya  Â·  3Comments

callumacrae picture callumacrae  Â·  3Comments

chansecampbell picture chansecampbell  Â·  3Comments

QJan84 picture QJan84  Â·  3Comments

danielcpereira11 picture danielcpereira11  Â·  4Comments