Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

317
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda