Generate Random Color JS

Source: Internet
Author: User

Peacetime practice, often add color to highlight the effect, I feel very troublesome, and I can remember the color is not many, but also bad choice, so I made the following to generate random color JS code

<! DOCTYPE html>
<meta charset= "Utf-8"/>
<title> two columns three-column adaptive layout </title>
<style type= "Text/css" >

/* Two column three-column adaptive layout */

/* Two column layout main bar left column right */
. g-mn1{float:left;width:100%;margin-right:-200px;}
. g-mnc1{margin-right:210px;}
. g-sd1{float:right;width:200px;}

/* Two column layout the right column of the main bar left */
. g-mn2{float:right;width:100%;margin-left:-200px;}
. g-mnc2{margin-left:210px;}
. g-sd2{float:left;width:200px;}

/* Three column layout main bar right side bar left */
. g-mn3{float:right;width:100%;margin-left:-520px;}
. g-mnc3{margin-left:520px;}
. g-sd3a{float:left;width:300px;margin-right:10px;}
. g-sd3b{float:left;width:200px;}

/* Three-column layout in the main column of the side of the column separation around * *
. g-mn4{float:right;width:100%;margin-left:-200px;}
. g-mnc4{margin-left:210px;}
. g-sd4{float:left;width:200px;}
. g-mn5{float:left;width:100%;margin-right:-200px;}
. g-mnc5{margin-right:210px;}
. g-sd5{float:right;width:200px;}

</style>
<body>

<div class= "G-BD" >
<div class= "G-mn1" >
<div class= "G-mnc1" >
<p> Main bar 1 content area </p>
</div>
</div>
<div class= "G-SD1" >
<p> Sidebar 1 content area </p>
</div>
</div>
<div class= "G-BD" >
<div class= "G-mn2" >
<div class= "G-mnc2" >
<p> Main bar 2 content area </p>
</div>
</div>
<div class= "G-SD2" >
<p> Sidebar 2 content area </p>
</div>
</div>
<div class= "G-BD" >
<div class= "G-mn4" >
<div class= "G-mnc4" >
<div class= "G-mn5" >
<div class= "G-mnc5" >
<p> Main Bar 5 content area </p>
</div>
</div>
<div class= "G-SD5" >
<p> Sidebar 5 content area </p>
</div>
</div>
</div>
<div class= "G-SD4" >
<p> Sidebar 4 content area </p>
</div>
</div>
<div class= "G-BD" >
<div class= "G-mn3" >
<div class= "G-mnc3" >
<p> Main bar 3 content area </p>
</div>
</div>
<div class= "G-SD3A" >
<p> Sidebar a content area </p>
</div>
<div class= "g-sd3b" >
<p> side bar B content area </p>
</div>
</div>


</body>
<script>

function ProductColor (ele) {

for (i=0; i<ele.length; i++) {
var addition = [];

for (var k=0; k<3; k++) {
for (j=0; j<2000; J + +) {
if (addition.length = = 3) {
Break
}
var rdm1 = Math.random (). toFixed (1) * 10;
var rdm2 = Math.random (). toFixed (1) * 10;
var rdm3 = Math.random (). toFixed (1) * 10;
var addit = number (rdm1.tostring () + rdm2.tostring () + rdm3.tostring ());
if (Addit > 0 && addit < 255) {
Addition.push (Addit);
}else{
Continue
}
}
}
Ele[i].style.backgroundcolor = "RGB (" + addition.tostring () + ")";
}
}

ProductColor (document.getElementsByTagName ("div")); /* Generate a color function, parameter is an array of elements that need to generate a color */

</script>

Generate Random Color JS

Related Article

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.