Why doesn't the center element (with the lowest translateZ
value) always appear on top?
http://codepen.io/robgordon/pen/BKzVOp
<div class="carousel">
<div class="item one">hello</div>
<div class="item two">hello</div>
<div class="item three">hello</div>
</div>
$height: 200px;
.carousel {
display: block;
position: relative;
width: 100%;
height: $height;
perspective: 800px;
}
.item {
height: $height;
width: 50%;
display: block;
position: absolute;
transform-style: perspective-3d;
transition: all 500ms linear;
backface-visibility: hidden;
&:nth-child(1) {
background: red;
}
&:nth-child(2) {
background: green;
}
&:nth-child(3) {
background: blue;
}
&.one {
transform: translateX(0%) translateZ(-100px);
}
&.two {
transform: translateX(50%) translateZ(0px);
}
&.three {
transform: translateX(100%) translateZ(-100px);
}
}
Number.prototype.mod = function(n) {
return ((this%n)+n)%n;
};
setInterval(function() {
var left = $('.one'),
center = $('.two'),
right = $('.three');
$(left).removeClass('one').addClass('two');
$(center).removeClass('two').addClass('three');
$(right).removeClass('three').addClass('one');
}, 2000);