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

132
Visualizações
jQuery animation out of sync after switching pages

I'm trying to make a page where the text changes, and between each text I use a fade in and fade out, and this works perfectly, however when I change the window this animation is delayed, but the .html that is the that I use to change the text doesn't delay, and ends up getting everything out of sync.

Does anyone know any solution for this?

This is my JS code

$(document).ready(() => {
  let ms = 8000
  let textQueue = ['1', '2', '3']
  for (let index = 0; index < textQueue.length; index++) {
    ((index) => {
      setTimeout(() => {
        if (index == textQueue.length - 1) {
          $(".text").click(() => {
            window.open('link')
          })
        }
        $(".text")
          .html(textQueue[index])
          .fadeIn(1500)
          .delay(5000)
          .fadeOut(1500)
      }, ms * index)
    })(index)
  }
})
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I managed to solve this and improved the code, I'll leave it here in case anyone needs it.
Basically I set it to change the text only when the fadeOut animation ends.

JS code:

$(document).ready(() => {
  let ms = 8000
  let textQueue = [
    '0',
    '1',
    '2'
  ]

  let index = 0
  $(document).click(() => {
    if (index + 1 === textQueue.length) {
      window.open('link')
      return
    }
    index++
    $(".text").html(textQueue[index])
  })
  animation()

  function animation() {
    if (index < textQueue.length) {
      $(".text").fadeOut(1500, () => {
        $(".text").html(textQueue[index])
      })
    }
    $(".text")
      .fadeIn(1500)
      .delay(5000)
    setTimeout(() => {
      if (index < textQueue.length - 1) {
        index++
        animation()
      }
    }, 8000)
  }
})
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