Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

212
Vistas
Change swiper-slide background (Swiper.js) when in darkmode, next.js + tailwindcss darkmode

I am using next.js with tailwindcss and Swiper js. I have also implemented a darkmode functionallity. So basically I want to change the background-color of all divs with the class of swiper-slide. I have some png images in every swiper slide and when i toggle the darkmode on I need the background of the swiper-slide to change. So I want to add the class of let say dark:bg-blue-900. I have tried grabbing the swiper-slides in useEffect by using querySelector all and then using a for of loop to add the classes, but the classes doesn't seem to be applied at all when I inspect the elements. How can I add the class? Here is my component

export default function VerticalSwiper() {
  const content = [
    { id: 1, img: PizzaImg },
    { id: 2, img: HamburgerImg },
    { id: 3, img: SteakImg },
    { id: 4, img: Salad1Img },
    { id: 5, img: WineImg },
    { id: 6, img: KebabImg },
    { id: 7, img: SodaImg },
    { id: 8, img: BeerImg },
    { id: 9, img: Salad2Img },
  ];

  useEffect(() => {
    const root = window.document.documentElement;
    if (root.classList.value === 'dark') {
      const swiperSlides = document.querySelectorAll('.swiper-slide');
      for (const swiperSlide of swiperSlides) {
        swiperSlide.classList.add('dark:bg-blue-900');
      }
    }
  });

  return (
    <div className="swiper-container">
      <Swiper
        direction={'vertical'}
        autoplay={{
          delay: 3500,
          disableOnInteraction: false,
        }}
        pagination={{
          clickable: true,
        }}
        modules={[Autoplay, Pagination]}
        className="mySwiper"
      >
        {content.map((item) => (
          <SwiperSlide key={item.id}>
            <SwiperContent img={item.img} />
          </SwiperSlide>
        ))}
      </Swiper>
    </div>
  );
}

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda