Home >Web Front-end >JS Tutorial >js code to return the color of the circular gradient using increasing numbers_javascript skills

js code to return the color of the circular gradient using increasing numbers_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:59:441604browse

The function is as follows:

Copy code The code is as follows:

function gCL(i){
var f=parseInt((i )/5);
i=i %5;
switch(f){
case 0:return "#" cS2(255-i*51) cS2 (i*51) "00";
case 1:return "#00" cS2(255-i*51) cS2(i*51);
case 2:return "#" cS2(i*51 ) "00" cS2(255-i*51);
}
}
function cS2(i) {
var s=i.toString(16);
return ("00 " s).substr(s.length);
}

Using gCL, you can use increasing numbers to return the gradient color from red to green to blue. The gradient effect is as follows, a total of 15 colors, cyclic gradient:

For example, in the following application, use this function to gradient the background color of a hyperlink:

[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute it
]
This function can be modified Produce more detailed color changes, interested friends can try it.
Statement:
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