Use incremented numbers to return the color of the loop gradient JS code _javascript Tips

Source: Internet
Author: User
The functions are as follows:
Copy Code code as follows:

function GCL (i) {
var f=parseint ((i%15)/5);
i=i%15%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) + "+CS2" (255-i*51);
}
}
function CS2 (i) {
var s=i.tostring (16);
Return ("+s"). substr (s.length);
}

Using GCL, you can use an incremented number to return a gradient color from red to green to blue. The gradient effect is as follows, a total of 15 colors, cycle gradients:

For example, use this function to gradient the background color of a hyperlink:
Home <script language=jscript> <!--function GCL (i) {var f=parseint ((i%15)/5); i=i%15%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) + "+CS2" (255-i*51); }} function CS2 (i) {var s=i.tostring (16); Return ("+s"). substr (s.length); var A=document.getelementbyid (' a ') var sd=0; var cancel=0; function Colorful () {A.STYLE.BACKGROUNDCOLOR=GCL (sd++); if (!cancel) settimeout (' Colorful () ', 50); }--> </Script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

This function can also be modified to produce more detailed color changes, interested friends can try.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.