Home > Web Front-end > JS Tutorial > body text

Javascript calculation gradient color example sharing

小云云
Release: 2018-02-03 13:43:45
Original
1917 people have browsed it

This article mainly introduces relevant information to you about the examples of javascript calculating gradient color. I hope this article can help you understand and master this part of the content. Friends who need it can refer to it. I hope it can help you.

Instance of javascript calculating gradient color

Sometimes, within a table or an area, several colors of the same color system from light to dark are needed, as shown in the figure As shown:

If few colors are needed, the color difference will be large; if more colors are needed, the color difference will be small, as shown below:


At this time, the calculation of the gradient color of the same color system is used. The algorithm is as follows:


function getItemColors (colorLevel) { 
  var colors= []; 
  //默认的最深颜色 
  var red = 134,green = 108, blue = 184; 
  //最浅颜色是239,239,239 比如:最浅颜色的red是 239 则差值为239-134=105 
  var maxRed = 105,maxGreen = 131,maxBlue = 55; 
  var level = colorLevel; 
  while(level--) { 
    colors.push( 'rgb('+red +','+green+','+blue+')'); 
    red += parseInt(maxRed/colorLevel); 
    green += parseInt(maxGreen/colorLevel); 
    blue += parseInt(maxBlue/colorLevel); 
  } 
  return colors; 
}
Copy after login

Related recommendations:

html5 canvas drawing radioactive gradient color effect code example

Color value RGBA and gradient in CSS3 Detailed explanation of color (picture)

div+css background gradient color code example

The above is the detailed content of Javascript calculation gradient color example sharing. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template