JavaScript implements gradient effect (no image) _ page background

Source: Internet
Author: User
JavaScript fades in color without using images, which saves time and saves the trouble of using images, and consumes a very small amount of resources. The fades in color are even and beautiful, and I am stunned, it is worth learning. Next we will introduce it in detail.

<Title> JavaScript gradient </title> <script language = "JavaScript1.2"> <! -- If (document. all) {one = new Array (); two = new Array (); var a = 10; var B = 11; var c = 12; var d = 13; var e = 14; var f = 15; var width = 350; var height = 20; var gap = 5; var direction = 0; // color number 1-enter 1st, 3rd and 5th numbers/letters of color code one [0] = f; one [1] = f; one [2] = 0; // color number 2-enter 1st, 3rd and 5th numbers/letters of color code two [0] = 0; two [1] = c; two [2] = 0; // end configuration if (direction = 0) var num = width/gap; if (direction = 1) var num = height/gap; color2 = new Array (); color1 = new Array (); diff = new Array (); for (I = 0; I <3; I ++) {diff [I] = two [I]-one [I]; diff [I] = diff [I]/num;} for (I = 0; I <3; I ++) {color1 [I] = Math. round (diff [I] * Math. pow (10, 0); if (color1 [I]> diff [I]) color1 [I] = color1 [I]-1; color2 [I] = diff [I]-color1 [I]; color2 [I] = color2 [I] * 15; color2 [I] = Math. round (color2 [I] * Math. pow (10, 0);} x = new Array (); two [0] = 0; two [1] = 0; two [2] = 0; document. write ('<table border = "0" cellpadding = "0" cellspacing = "0" width = "' + width + '" height = "' + height + '">' ); if (direction = 0) document. write ('<tr>'); for (I = 0; I <= num; I ++) {if (direction = 1) document. write ('<tr>'); document. write ('<td bgcolor = "#'); for (j = 0; j <3; j ++) {if (one [j] = a) document. write ("a"); if (one [j] = B) document. write ("B"); if (one [j] = c) document. write ("c"); if (one [j] = d) document. write ("d"); if (one [j] = e) document. write ("e"); if (one [j] = f) document. write ("f"); if (one [j] <10) document. write (one [j]); if (two [j] = a) document. write ("a"); if (two [j] = B) document. write ("B"); if (two [j] = c) document. write ("c"); if (two [j] = d) document. write ("d"); if (two [j] = e) document. write ("e"); if (two [j] = f) document. write ("f"); if (two [j] <10) document. write (two [j]); one [j] = one [j] + color1 [j]; two [j] = two [j] + color2 [j]; if (two [j]> 15) {two [j] = two [j]-15; one [j] ++ ;}} if (direction = 0) document. write ('"width ="' + gap + '"height ="' + height + '"> </td>'); if (direction = 1) document. write ('"width ="' + width + '"height ="' + gap + '"> </td> </tr>');} document. write ('</table>');} // --> script
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]

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.