swiper icon indicating copy to clipboard operation
swiper copied to clipboard

Swiper Thumbs Gallery Loop - making issue for thumbs & onSwiper

Open dhavalveera opened this issue 3 years ago • 9 comments

Hello,

<Swiper loop={true}  spaceBetween={10} autoplay={{ delay: 3000 }} rewind={true} thumbs={{ swiper: thumbsSwiper }} modules={[Autoplay, FreeMode, Thumbs]} className="mySwiper2" >
     <SwiperSlide>...</SwiperSlide>
</Swiper>
<Swiper loop={true} slidesPerView={3} spaceBetween={25} freeMode={true} watchSlidesProgress={true} modules={[ Autoplay, FreeMode, Navigation, Thumbs ]} className="mySwiper" autoplay={{ delay: 3000 }} rewind={true} >
    <SwiperSlide>...</SwiperSlide>
</Swiper>

then in my Nextjs Web App, it's following the below error.

image

please help me

dhavalveera avatar Aug 19 '22 11:08 dhavalveera

This is because thumbsSwiper has not been initialized yet.

Try this:

thumbs={{ swiper: thumbsSwiper && !thumbsSwiper.destroyed ? thumbsSwiper : null }}

aso1datov avatar Sep 02 '22 14:09 aso1datov

@aso1datov == Thanks, your solution is working now...

I've one more thing to ask when an Image is active on both the sliders, then in the Thumbs Slider (2nd slider) I want to show some Icon on the Image for one which one is active/selected, can you able to help me how it's possible?

dhavalveera avatar Sep 05 '22 06:09 dhavalveera

Try this:

.swiper-slide-thumb-active img  {
    /* your styles */
}

aso1datov avatar Sep 05 '22 06:09 aso1datov

as I am using in Next.js, so that'll be in global CSS, right?

dhavalveera avatar Sep 05 '22 06:09 dhavalveera

@aso1datov - I tried but it's not working...

dhavalveera avatar Sep 05 '22 07:09 dhavalveera

Check if your styles are overwritten by inline css.

In my case I did it like this:

.thumbnails {
  :global(.swiper-slide-thumb-active)::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border: 2px solid #3772ff;
    pointer-events: none;
    z-index: 1;
  }
}

.thumbnail {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  cursor: pointer;
}
 <Swiper
  className={styles.thumbnails}
  spaceBetween={8}
  slidesPerView={6}
  threshold={5}
  modules={modules}
  onSwiper={setThumbsSwiper}
  freeMode={true}
  watchOverflow={true}
  watchSlidesProgress={true}
>
  {game.screenshots.map((cover) => (
    <SwiperSlide key={cover}>
      <div className={styles.thumbnail}>
        <Image
          src={cover}
          alt={game.title}
          layout="fill"
          objectFit="cover"
          objectPosition="center"
        />
      </div>
    </SwiperSlide>
  ))}
</Swiper>

aso1datov avatar Sep 05 '22 10:09 aso1datov

NO, I am not overriding any CSS Codes for <Swiper> as well as for <SwiperSlide>

in your case, as in .thumbnails for CSS, inside of .thumbnais {} you're writing global, so that's with CSS3 or with SCSS/SASS?

dhavalveera avatar Sep 05 '22 10:09 dhavalveera

It's css-modules feature

aso1datov avatar Sep 05 '22 13:09 aso1datov

@aso1datov --- the CSS code you wrote above, I tried the same here in my local, but it's not working

dhavalveera avatar Sep 07 '22 03:09 dhavalveera

@aso1datov ---- I am using a thumb swiper slider, my requirement is I have 30 images and I click the 3rd Image and the 3rd Image has to display without sliding other Images. I am stuck with an issue can you Help us?

Chandra-Sekhar-Korni avatar Oct 07 '22 08:10 Chandra-Sekhar-Korni

Swiper v9 comes with fully reworked and now different loop functionality. If you have similar issues in Swiper 9, open a new issue with a CodeSandbox showing the issue.

nolimits4web avatar Feb 01 '23 11:02 nolimits4web