I attempted to implement image rotation using google jquery library. The problem is that the image
rotation stops at 5.jpg and doesn't go back to 1.jpg to 2.jpg.........and so on. Did I miss out
something?
<html>
<head>
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js?ver=3.0.1">
</script>
<script type="text/javascript" src="js/img-rotator.js">
</script>
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" />
</head>
<body>
<div id="rotating-img-container">
<img class="rotating-img-item" src="images/1.jpg" />
<img class="rotating-img-item" src="images/2.jpg" />
<img class="rotating-img-item" src="images/3.jpg" />
<img class="rotating-img-item" src="images/4.jpg" />
<img class="rotating-img-item" src="images/5.jpg" />
</div>
</body>
</html>
$(window).load(function(){
var rotator = {
init: function(){
var imgCount = $('.rotating-img-item').length;
var currentImg = 0;
$('.rotating-img-item').eq(currentImg).fadeIn(1000);
var loop = setInterval(function(){
$('.rotating-img-item').eq(currentImg).fadeIn(1000);
if(currentImg == imgCount - 1){
currentImg = 0;
}else{
currentImg++;
}
$('.rotating-img-item').eq(currentImg).fadeIn(1000);
},5000);
}
};
rotator.init();
});
#rotating-img-container {
position: relative;
width: 980px;
height: 347px;
}
.rotating-img-item {
display: none;
position: absolute;
top: 0;
left: 0;
}