E
eefacm
I'm composing a simple page that consists largely of a series of
images. Many of the images appear in groups showing the successive
stages of a particular operation. I thought it might look nice to
stack up the images, so that clicking on the topmost image sends it to
the bottom of the stack, showing the image that had been just below
it. Here's my first crack at it, for the simplest case of just two
images:
<style type="text/css">
.cycle { position: relative }
.cycle img { position: absolute; z-index: 1 }
.cycle img + img { top: 2em; left: 2em; z-index: 0 }
</style>
<script type="text/javascript">
function mouseclick(event) {
var target = event.target;
var parent = target.parentNode;
if (target.tagName == "IMG" && parent.className == "cycle") {
parent.appendChild(target);
}
}
document.addEventListener("click", mouseclick, false);
</script>
....
<div class="cycle">
<img src="image1.png">
<img src="image2.png">
</div>
This gives the overlapping visual effect I was after. When I click on
the top image, it jumps down into the lower position, completely
obscuring the lower image, but the lower image does NOT move into the
upper position. I had been expecting that after the appendChild
operation, with the second child of the div now becoming the first
child, the third style rule would no longer be applied to it, but
something about my expectation is clearly incorrect. Anyone have any
idea what might that be?
images. Many of the images appear in groups showing the successive
stages of a particular operation. I thought it might look nice to
stack up the images, so that clicking on the topmost image sends it to
the bottom of the stack, showing the image that had been just below
it. Here's my first crack at it, for the simplest case of just two
images:
<style type="text/css">
.cycle { position: relative }
.cycle img { position: absolute; z-index: 1 }
.cycle img + img { top: 2em; left: 2em; z-index: 0 }
</style>
<script type="text/javascript">
function mouseclick(event) {
var target = event.target;
var parent = target.parentNode;
if (target.tagName == "IMG" && parent.className == "cycle") {
parent.appendChild(target);
}
}
document.addEventListener("click", mouseclick, false);
</script>
....
<div class="cycle">
<img src="image1.png">
<img src="image2.png">
</div>
This gives the overlapping visual effect I was after. When I click on
the top image, it jumps down into the lower position, completely
obscuring the lower image, but the lower image does NOT move into the
upper position. I had been expecting that after the appendChild
operation, with the second child of the div now becoming the first
child, the third style rule would no longer be applied to it, but
something about my expectation is clearly incorrect. Anyone have any
idea what might that be?