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

183
Vistas
How to track the completion of a function and add a click event handler?

How can I make the click event handler speed up the type function and then replace the text with the desired one?

Each type () function runs on scrolling if the block comes into view

My code

https://jsfiddle.net/sp_true/b5rj8mvd/4/

 function typeCode(lineItem) {
    const codeLine = lineItem.querySelector(".type"),
      columnBlock = lineItem.querySelector(".column"),
      code = codeLine.innerHTML,
      lengthContent = lineItem.querySelector(".hide-text").innerHTML.split('br').length

    let str = code,
      i = 0,
      isTag,
      text;
    columnBlock.innerHTML = Array(lengthContent + 1).fill(0).map((_, i) => `<span>${i+1}</span>`).join('<br>');

    (function type() {
      text = str.slice(0, ++i);
      if (text === str) return;

      lineItem.querySelector('.type').innerHTML = text;
      let char = text.slice(-1);
      if (char === '<') isTag = true;
      if (char === '>') isTag = false;

      if (isTag) return type();
      setTimeout(type, 40); // Here is speed to All Block left anim (60)
    }());
  }
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