André Laugks: Problem mit mehrerer positionierten Grafiken per DIV STYLE

Beitrag lesen

Hallo!

source = '<div style="position:absolute;; left:100px; top:100px; z-index:1">';
source += '<img src="Grafik1.jpg" border="0" alt="">';
source += '</div>';

Bis hier OK!

source = '<div style="position:absolute; left:100px; top:200px; z-index:2">';

Hier "löschst" Du den String (erster Layer) in der Variable source und speicherst den zweiten Layer, weil
Du den zweiten Layer nicht mit += anhängst.

So sollte es richtig lauten:
source += '<div style="position:absolute; left:100px; top:200px; z-index:2">';

source = '<div style="position:absolute; left:100px; top:400px; z-index:4">';

Deshalb sieht man auch nur den dritten Layer.
Wegen dem "=", löschst Du den gesamten String(erster und zweiter Layer), der in der Variable source enthalten ist.

Komplet richtig ist es so:

source = '<div style="position:absolute;; left:100px; top:100px; z-index:1">';
source += '<img src="Grafik1.jpg" border="0" alt="">';
source += '</div>';
source += '<div style="position:absolute; left:100px; top:200px; z-index:2">';
source += '<img src="Grafik2.jpg" width="347" height="38" border="0" alt="">';
source += '</div>';
source += '<div style="position:absolute; left:100px; top:300px; z-index:3">';
source += '<img src="Grafik3.jpg" width="347" height="38" border="0" alt="">';
source += '</div>';
source += '<div style="position:absolute; left:100px; top:400px; z-index:4">';
source += '<img src="Grafik4.jpg" width="347" height="38" border="0" alt="">';
source += '</div>';
document.write(source);

mfg, André Laugks