Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

109
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!