Hallo,
mit Hilfe von Mathias Schäfers Beitrag zu closures (habs nicht ganz kapiert, aber nachgebaut):
window.onload = function () {
layer2 = new divChange("layer2");
setTimeout ("layer2.changeZindex()",1000);
layer3 = new divChange("layer3");
setTimeout ("layer3.changeZindex()",2000);
layer1 = new divChange("layer1");
setTimeout ("layer1.changeZindex()",3000);
}
function divChange(masterDivId) {
var thisObject = this;
var masterDiv = document.getElementById(masterDivId);
this.timeInterval = 3000;
this.containedDivs = masterDiv.getElementsByTagName("div");
this.count = 0;
zIndex = 10;
this.changeZindex = function () {
if (thisObject.count == thisObject.containedDivs.length) {
thisObject.count = 0;
}
zIndex += 1;
thisObject.containedDivs[thisObject.count].style.zIndex = zIndex;
thisObject.count++;
window.setTimeout(thisObject.changeZindex,thisObject.timeInterval);
}
}
Gruß
jobo