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

322
Vistas
How can I make animated lines between Swiper slides with leader-line js?

I am trying to build a timeline with Swiper and leader-line.js. I tried to use it with Swiper's on transition funcitons but it doesn't work properly. Here is my Leader-line code;

const items = document.querySelectorAll(".circle");
const options = {
  startSockets: ["top", "bottom", "right", "bottom", "left", "right"],
  endSockets: ["top", "bottom", "top", "top", "top", "top"]
};

for(let i = 0; i < items.length - 1; i++) {
  new LeaderLine(items[i], items[i + 1], {
    startPlug: "behind",
    endPlug: "behind",
    size: 2,
    dash: true,
    startPlugSize: 3,
    endPlugSize: 1,
    startSocket: "right",
    endSocket: "left",
    color: "#fb8c00",
    path: 'straight',
  });
}

I made an codepen example to make it clear.

https://codepen.io/Xteripus/pen/yLopBNp?editors=1010

I want to make lines stick to Swiper's container so when swiper element moves the line moves with it. Thanks in advance!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Anseki, developer of the plugin made this solution, hope it helps!

Here is js:

     $(".circle").each(function (index, el) {
    $(el).css({
        top: Math.random() * ($(".swiper-slide ").height() - 300 - $(this).height())
    });
    });
    const items = document.querySelectorAll(".circle");
    const options = {
    startSockets: ["top", "bottom", "right", "bottom", "left", "right"],
    endSockets: ["top", "bottom", "top", "top", "top", "top"]
    };

    const lines = [];
    for (let i = 0; i < items.length - 1; i++) {
    lines.push(
        new LeaderLine(items[i], items[i + 1], {
        startPlug: "behind",
        endPlug: "behind",
        size: 2,
        dash: true,
        startPlugSize: 3,
        endPlugSize: 1,
        startSocket: "right",
        endSocket: "left",
        color: "#fb8c00",
        path: "straight"
        })
    );
    }

    swiper.on("sliderMove", () => {
    lines.forEach((line) => {
        line.position();
    });
    });
    let req;
    function position(stop) {
    cancelAnimationFrame(req);
    lines.forEach((line) => {
        line.position();
    });
    if (stop !== true) {
        req = requestAnimationFrame(position);
    }
    }
    swiper.on("slideChangeTransitionStart", position);
    swiper.on("slideResetTransitionStart", position);
    swiper.on("slideChangeTransitionEnd", () => {
    position(true);
    });
    swiper.on("slideResetTransitionEnd", () => {
    position(true);
    });
    

https://codepen.io/anseki/pen/qBXpEWV?editors=1010

about 4 years ago · Juan Pablo Isaza Denunciar
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