I would like to create an effect where the background color of an icon changes randomly to match the color of the text. There are four predefined color choices available for this randomization.
Here is the current code I am working with:
HTML:
<div class="monobg">
<img src="http://chloesilver.ca/mono1.png" alt="mono1" />
</div>
CSS:
.monobg {
background-color: red;
padding:10px;
width:60px;
}
JS:
function random_imglink(){
var myimages=new Array();
//define text content below. Add as many entries as needed
myimages[1]="This is text1.";
myimages[2]="This is text2.";
myimages[3]="This is text3.";
myimages[4]="This is text4.";
myimages[5]="This is text5.";
myimages[6]="This is text6.";
var ry=Math.floor(Math.random()*myimages.length);
if (ry==0)
ry=1;
document.write('<p>'+myimages[ry]+'</p>');
}
document.addEventHandler("ready", function() {
random_imglink();
var bgcolorlist = new Array("silver", "#BAF3c3", "#c3baf3", "red");
document.body.style.color=bgcolorlist[Math.floor(Math.random()*bgcolorlist.length)];
});
I believe the following link might provide some insight, but it's unclear to me how it relates: Random Hex colour from an array