Hallo,
var BgChanger = {
start : function (elemId, rgbVals, rgbRanges, interval) {
var ColorHandler = {
red : {},
green : {},
blue : {},
style : {},
createColorObj : function (value, range) {
return {
"value": value,
"max" : value,
"range" : range,
"dir" : 1
};
},
nextVal : function (colorName) {
var c = this[colorName],
val = c.value,
max = c.max,
range = c.range;
if (val <= max - range || val >= max) {
c.dir *= -1;
}
c.value += c.dir;
return c.value;
},
change : function () {
this.style.backgroundColor = "RGB(" + this.nextVal("red") + "," + this.nextVal("green") + "," + this.nextVal("blue") + ")";
},
init : function (elemId, rgbVals, rgbRanges) {
this.style = document.getElementById(elemId).style;
this.red = this.createColorObj(rgbVals[0], rgbRanges[0]);
this.green = this.createColorObj(rgbVals[1], rgbRanges[1]);
this.blue = this.createColorObj(rgbVals[2], rgbRanges[2]);
}
};
ColorHandler.init(elemId, rgbVals, rgbRanges);
window.setInterval(function () {ColorHandler.change(); }, interval);
}
};
window.onload = function () {
BgChanger.start("bgchange", [255, 168, 136], [55, 10, 16], 120);
};
Gruß
jobo