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

110
Visualizações
Rotating font family with js

I'm very new to JS, I have a problem that could easily be solved I think but I can't figure it out :

I would like to find a way to change the font-family of an html element every 0.1 seconds without having to trigger something.

Basically I would like the html element to change font every 0.1 sec, rotating amongst 6 font families.

really thankful if you guys can find a way.

Louis

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Try something like :

function changefontFamily() {
  var doc = document.getElementById("elementID");
  var font= ["Arial", "Verdana", "Helvetica ", "Tahoma"];
  doc.style.fontFamily= font[i];
  i = (i + 1) % font.length;
}
setInterval(changefontFamily, 100);
<div id="elementID">text</div>
about 4 years ago · Juan Pablo Isaza Relatório

0

I set 1 second (1000 ms), for clarity, because 100ms is too fast 🙂

(async()=>{
    const elem = document.getElementById('elementID');
    const fonts = ['Arial', 'Tahoma', 'Verdana'];

    let k = fonts.length;
    setInterval(()=>{
        k--;
        elem.style.fontFamily = fonts[k];
        console.log('Now:', fonts[k], k);
        if(k === 0)k = fonts.length;
    }, 1000);
})();
<div id="elementID">Some Text to test it OUT</div>

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