question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

in loop mode, the component events can't be worked if swipe from the first slide to the last slide

See original GitHub issue

in loop mode, the component events can’t be worked if swipe from the first slide to the last slide. for example:

<Swiper {...params}>
  {
      imgList.map((list, i) =>
        <img key={i} onClick={this.onDocClick.bind(this, list.url)} src={list.imgUrl} />
      )
   }
 </Swiper>

the onClick method will worked as well in no-loop, but in loop mode, if swipe from the first slide to the last slide, it couldn’t worked. I know the Swiper will clone the first and the last of the element in loop mode, how to make it right in react?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

19reactions
crohrercommented, Sep 19, 2018

This is more a workaround than a real solution to the problem. This gets very messy when you need to track multiple events. Do you plan to implement a real fix, or are react-events in loop-mode not supported?

8reactions
razor1895commented, Dec 22, 2017

Because of nature of how the loop mode works, swiper will add duplicated slides, you will see a copy of last slide when you swipe from the first slide to the last. This copy is not under the manage of react, it will not respond to react events. So you need to add a click eventListener to handle this

componentDidMount() {
    const slides = document.querySelectorAll('.swiper-slide');
    const fakeFirstSlide = slides[slides.length - 1];
    const fakeLastSlide = slides[0];

    if (this.props.onClickFirstSlide) {
      fakeFirstSlide.addEventListener('click', this.props.onClickFirstSlide);
    }

    if (this.props.onClickLastSlide) {
      fakeLastSlide.addEventListener('click', this.props.onClickLastSlide);
    }
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

SwiperOptions | Swiper - v8.4.5
Event will be fired in the beginning of animation to other slide (next or previous). Parameters. swiper: default. Returns void. Optional slideNextTransitionEnd ...
Read more >
javascript - Swiper JS - show part of next slide - Stack Overflow
This one will show a partial view of the next and previous slide. In my case it's a full width carousel so I'm...
Read more >
Set Up Swiper.js for Angular Slides [Example] - Ionic Framework
We recommend Swiper.js if you need a modern touch slider component. ... First, update to the latest version of Ionic: ... Swiping with...
Read more >
Swiper - Basic Options - Wappler Documentation
The Swiper component in Wappler is a modern, touch-friendly slider which can ... loop mode, so when on last slide you click/swipe to...
Read more >
Vueper Slides - GitHub Pages
Vueper Slides is a Vue JS Slideshow / Carousel. ... If you want more control on events and button wrapper. ... Let's see...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found