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

157
Vistas
Re-initialise Slick slider with Swup

I am using Swup to create a page transition effects however it's breaking my slick slider. Currently it only works on page refresh but if I navigate to a different page and comeback it's broken. Looking at the documentation I understand that I have to re-load the JavaScript.

In my sliders.js file I have this:

import "slick-carousel";

const methodSlider = $(".slider-block .slider-wrapper");

export const ourMethodSlider = () => {
    methodSlider.not(".slick-initialized").slick({
        infinite: true,
        arrows: true,
        dots: true,
        prevArrow: $(".prev"),
        nextArrow: $(".next"),
    });
};

export const destroyMethodSlider = () => {
    if ($(methodSlider).hasClass("slick-initialized")) {
        $(methodSlider).slick("destroy");
        $(methodSlider)[0].slick.refresh();
    }
};

And then in my swup.js file I have this:

import Swup from "swup";
import "slick-carousel";

import { destroyMethodSlider, ourMethodSlider } from "./sliders";

function init() {
    ourMethodSlider();
}

function unload() {
    destroyMethodSlider();
}

init();

const swup = new Swup();

swup.on("contentReplaced", init);

swup.on("willReplaceContent", unload);

I also get no console errors.

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