Hi all
JS newbie here. I need help with looping through an array I have added to a script.
My array is called ‘Colours’ and contains 7 RGB values. The idea of the script is to change the background colour by fading the colours in the array into one another but I need it to be contiuous – thus the request for help!
Here is the code. Any help will be greatly appreciated.
[CODE]
<script language=”Javascript”>
var Colours = new Array()
Colours[0] = “212,180,135,146,147,149”
Colours[1] = “146,147,149,96,90,168”
Colours[2] = “96,90,168,100,185,227”
Colours[3] = “100,185,227,230,65,141”
Colours[4] = “230,65,141,247,172,4”
Colours[5] = “247,172,4,96,90,168”
Colours[6] = “96,90,168,176,202,53”
function StringArray (n) {
this.length = n;
for (var i =1; i <= n; i++) {
this[i] = ‘ ‘
}
}
fader = new StringArray(16)
for(var i = 0; i < 10; i++) {
fader[i] = i
}
fader[10] = “a”
fader[11] = “b”
fader[12] = “c”
fader[13] = “d”
fader[14] = “e”
fader[15] = “f”
function hexadecimal(i) {
return (“” + fader[Math.floor(i/16)] + fader[i%16])
}
function fade(r2,g2,b2,r1,g1,b1) {
for(var i = 0; i <= speed; i++) {
var r = hexadecimal(Math.floor(r2 * ((speed-i)/speed) + r1 * (i/speed)))
var g = hexadecimal(Math.floor(g2 * ((speed-i)/speed) + g1 * (i/speed)))
var b = hexadecimal(Math.floor(b2 * ((speed-i)/speed) + b1 * (i/speed)))
document.bgColor = “#” + r + g + b
}
}
</script>
When its not in a loop, the colours are called as such:
[CODE]
<script language=”Javascript”>
fade(212,180,135,146,147,149);
fade(146,147,149,96,90,168);
fade(96,90,168,100,185,227);
fade(100,185,227,230,65,141);
fade(230,65,141,247,172,4);
fade(247,172,4,96,90,168);
fade(96,90,168,176,202,53);
fade(212,180,135,146,147,149);
fade(146,147,149,96,90,168);
fade(96,90,168,100,185,227);
fade(100,185,227,230,65,141);
fade(230,65,141,247,172,4);
fade(247,172,4,96,90,168);
fade(96,90,168,176,202,53);
</script>