下面的例子len是实际item的长度。
lunbo:function (time){
var topIn =$('#content_top');
var oli = $('#content_top .top_item');
var len = oli.length;
var topPo = $('#top_po');
var index = 0;
var int = null;
for(var i=0;i<len;i++){
topPo.append("<li></li>");
};
var first = oli.eq(0).clone();
topIn.append(first);
var minLi = topPo.find('li');
minLi.eq(0).addClass('on')
topIn.css('width',(oli.length+1)*1060)
minLi.click(function(){
index = $(this).index();
topIn.css("left",index*1060*-1+"px");
$(this).addClass('on').siblings().removeClass('on')
})
topIn.mouseenter(function(){
clearInterval(int);
}).mouseleave(function(){
int = setInterval(run,time);
})
topPo.mouseenter(function(){
clearInterval(int);
}).mouseleave(function(){
int = setInterval(run,time);
})
int = setInterval(run,time)
function run(){
index++;
if(index>len){
topIn.stop().css("left",0);
index =1;
}
if(index==len){ //5
topIn.animate({
left:parseInt(topIn.css('left'))-1060+"px"
},500)
minLi.eq(0).addClass('on').siblings().removeClass('on');
}
if(index<len){
topIn.animate({
left:parseInt(topIn.css('left'))-1060+"px"
},500)
minLi.eq(index).addClass('on').siblings().removeClass('on');
}
}
},