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

175
Views
Continuous Rainbow color cycling effect in js

Just started learning JS and want to know how to create an effect in which VIBGYOR color keeps on cycling continuously using JS. Here is my attempt https://jsfiddle.net/2t1kbm8u/.

const scheme = document.querySelector("div");
const rainbow = [
  "#9400D3",
  "#4B0082",
  "#0000FF",
  "#00FF00",
  "#FFFF00",
  "#FF7F00",
  "#FF0000",
];

setInterval(() => {
  for(let colors = 0; colors < rainbow.length; colors++) {
    scheme.style.color = `${rainbow[colors]}`;
    scheme.style.borderColor = `${rainbow[colors]}`;
    console.log(rainbow[colors]);
  }
}, 1000);

Though all colors are being consoled but only the first and last colors are visible

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

   const scheme = document.querySelector("div");
  const rainbow = [
    "#9400D3",
    "#4B0082",
    "#0000FF",
    "#00FF00",
    "#FFFF00",
    "#FF7F00",
    "#FF0000",
  ];
  var currentColor = 0;
  setInterval(() => {
    scheme.style.color = `${rainbow[currentColor]}`;
    scheme.style.borderColor = `${rainbow[currentColor]}`;
    currentColor++; 
    if (currentColor == rainbow.length-1) {
    currentColor = 0;
    }
  }, 1000);
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!