Giter Club home page Giter Club logo

Comments (7)

crohrer avatar crohrer commented on August 27, 2024 19

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?

from react-id-swiper.

razor1895 avatar razor1895 commented on August 27, 2024 8

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);
    }
  }

from react-id-swiper.

gareys avatar gareys commented on August 27, 2024 1

After thinking more about this. I attempted to use loop mode and noticed that it doesn't work very well in my implementation. Soon, I will be working on making loop mode work in a project of mine and will update this with details.

from react-id-swiper.

gareys avatar gareys commented on August 27, 2024

try wrapping your swiper slides with a div. Let's see if that helps.

<div key={i}>
  <img ... />
</div>

from react-id-swiper.

OmgDef avatar OmgDef commented on August 27, 2024

Faced the same issue. Wrapping into with div doesn't help.

from react-id-swiper.

zxllzw avatar zxllzw commented on August 27, 2024
onClickFirstSlide

where is onClickFirstSlide & onClickLastSlide?

from react-id-swiper.

zeejay09 avatar zeejay09 commented on August 27, 2024

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);
    }
  }

How to implement this if slidesPerView is set to auto and instead of onClick, the listener used is onMouseEnter and onMouseOut?

from react-id-swiper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.