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

177
Visualizações
Pause animation not working in GSAP (GreenSock)

I'm new with GSAP (greensock), I created this text slide animation and it's working fine but I want it to play/pause on button click, for some reason it's not working as required.

let cT;

let changeText = () => {
  let cText = gsap.utils.toArray('.text');
  gsap.set(cText, { autoAlpha: 1 });

  cText.forEach((obj, i) => {
    cT = gsap.timeline({
      delay: 0.5 * i + 3 * i,
      repeat: -1,
      repeatDelay: (cText.length - 1) * (3.5) - 0.5,
      defaults: {
        ease: 'none',
        duration: 0.5,
      },
    });
    cT.from(obj, { yPercent: -60, opacity: 0 });
    cT.to(obj, { yPercent: 60, opacity: 0 }, '+=' + 3);
   
  });
};

changeText()


let pauseBtn = document.getElementById('pause');

pauseBtn.onclick = function () {
  cT.paused(!cT.paused());
  pauseBtn.innerHTML = cT.paused() ? 'Play' : 'Pause';
};
.side-text {
  position: relative;
}

.text {
  position: absolute;
  visibility: hidden;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.10.4/gsap.min.js"></script>
     <div class="side-text">
            <h5 class="text">First</h5>
            <h5 class="text">Second</h5>
            <h5 class="text">Third</h5>
            <h5 class="text">Fourth</h5>
          </div>
          
       <div class="text-center">
      <button type="button" id="pause" class="btn btn-primary">Pause</button>
    </div>

Thanks! will appreciate any help.

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