Пока я делал роторатор изображений jQuery, я столкнулся с проблемой.Где эта проблема?
http://jsfiddle.net/thisizmonster/6a6fv/3/
$(function() {
setInterval(function(){
var currentImg = $(".background-image img.active").attr("rel");
var nextImg = (currentImg != $(".background-image img").length) ? currentImg++ : 1;
//alert(nextImg );
$(".background-image img[rel="+currentImg+"]").removeClass("active");
$(".background-image img[rel="+nextImg+"]").addClass("active");
}, 3000);
});
CSS:
.background-image {
position: relative;
}
.background-image img {
position: absolute;
top: 0px;
left: 0px;
z-index: 1;
}
.background-image img.active {
z-index: 2;
}
HTML:
<div class="background-image">
<img src="http://lorempixel.com/400/200/sports" rel="1" width="400" height="200" class="active">
<img src="http://lorempixel.com/400/200/animals" rel="2" width="400" height="200">
<img src="http://lorempixel.com/400/200/city" rel="3" width="400" height="200">
</div>