Hallo,
sähe dann so aus:
function createColorHandler(style, colorProp, rgb, rgbRanges) {
function createColorObj(v, r) {
var value = v, max = v, range = r, dir = 1;
return function () {
if (value <= max - range || value >= max) {
dir *= -1;
}
value += dir;
return value;
};
}
var nextRed = createColorObj(rgb[0], rgbRanges[0]),
nextGreen = createColorObj(rgb[1], rgbRanges[1]),
nextBlue = createColorObj(rgb[2], rgbRanges[2]);
return function () {
style[colorProp] = "RGB(" + nextRed() + "," + nextGreen() + "," + nextBlue() + ")";
};
}
window.onload = function () {
var myBody = document.getElementsByTagName("body")[0];
window.setInterval(createColorHandler(myBody.style, "backgroundColor", [255, 168, 136], [55, 10, 16]), 120);
};
Gruß
jobo