Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

generate random hsl color values

function makeColor(colorNum, colors){
    if (colors < 1) colors = 1;
    // defaults to one color - avoid divide by zero
    return colorNum * (360 / colors) % 360;
}
// This could be length of your array.
var totalDIVs = 20;
var totalColors = totalDIVs;

for (var i = 0; i < totalDIVs; i++){
    var element = document.createElement('div');
    document.body.appendChild(element);
    var color = "hsl( " + makeColor(i, totalColors) + ", 100%, 50% )";
    element.style.backgroundColor = color;
    element.innerHTML = color;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: js number 123 to string one two three 
Javascript :: print from mongo console to file sample.json 
Javascript :: SayHello 
Javascript :: extend static class javascript 
Javascript :: why I can not insert image with ajax request 
Javascript :: video pop js 
Javascript :: mouseover event in angular 11 
Javascript :: initial min js 
Javascript :: ?. javascript 
Javascript :: regex reuse pattern 
Javascript :: creating a read stream from a large text file 
Javascript :: 1.047222170078745 
Javascript :: state creation in class components reactjs interview questions 
Javascript :: check if div is collpased jqeruy 
Javascript :: File to XHR-requests 
Javascript :: javascript only works in codepen 
Javascript :: print map object nodejs 
Javascript :: position of element related to parent div in jquery 
Javascript :: Checking equality with Promise.resolve vs async return 
Javascript :: correctly type checking objects in javascript 
Javascript :: react app link description preview 
Javascript :: discord.js ban 
Javascript :: signin with google widget floating automatically 
Javascript :: clima 
Javascript :: get keyword in javascript 
Javascript :: Using Scrip as Web app 
Javascript :: alegato termino excluido 
Javascript :: Grunt--project configuration object--uglify 
Javascript :: express serve node module 
Javascript :: javascript to python converter online 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =