$(function(){
var $box=$('.slide'),
$li=$box.find('li'),
len=$li.length,
count=0,
$point,
timer;
// 创建点
function createpoints(len){
var pointstr='
';
for(var i=0;i";
}else{
pointstr+="";
}
}
pointstr+='
';
var $points=$(pointstr).appendto($box);
$point=$points.find('li');
$point.hover(function(){
clearinterval(timer);
count=$point.index($(this));
move();
},function(){
timer=setinterval(function(){
next();
},5000);
});
}
createpoints(len);
// 初始化
$li.hide().eq(0).show();
// 动画
function move(){
$point.removeclass('selected').eq(count).addclass('selected');
$li.stop(true,true).fadeout(1000).eq(count).stop(true,true).fadein(1000);
}
// 向前
function next(){
if(count>=len-1){
count=0;
}else{
count++;
}
move();
}
// 向后
function back(){
if(count<=0){
count=len-1;
}else{
count--;
}
move();
}
// 自动
timer=setinterval(function(){
next();
},5000);
// 初始化箭头
var $arrows=$('.slide-arrow');
$arrows.hide();
$box.hover(function(){
$arrows.show();
},function(){
$arrows.hide();
})
// 绑定点击事件
$arrows.eq(0).click(function(){
clearinterval(timer);
back();
timer=setinterval(function(){
next();
},5000);
});
$arrows.eq(1).click(function(){
clearinterval(timer);
next();
timer=setinterval(function(){
next();
},5000);
});
})