jqeury之轮播图

 $(document).ready(function(){

 var sWidth = $('#pic1').width();
 var len = $('#pic1 .sildebar li').length;
 var timer;
 var index = 0;

 var focusBox = '<ul class="focusBox clearfix"></ul>';
 $('#pic1').append(focusBox);

 //生成底部焦点
 for(var i=0;i<len;i++){
 	var li = document.createElement('li');
    $('.focusBox')[0].appendChild(li);
 }

  //点击圆点时,进行切换
 $('#pic1 .focusBox li').click(function(){
 	index = $('#pic1 .focusBox li').index(this);
 	showPic(index);
 }).eq(0).trigger('click');
 
 $('#pic1 .sildebar').css("width",sWidth * (len));

//定时器,定时进行切换
 $('#pic1').hover(function(){
 	clearInterval(timer);
    },function(){
	 	timer = setInterval(function(){
	 	showPic(index);
	 	index++;
	 	if(index == len){index = 0;}
        },2000);
 }).trigger('mouseleave');

 function showPic(index){
 	var nowLeft = -index * sWidth;
 	$('#pic1 .sildebar').stop(true,false).animate({left:nowLeft},1000);
 	$('#pic1 .focusBox li').removeClass('cur').eq(index).addClass('cur');
      }
});

  

posted @ 2016-10-13 14:49  尘梦  阅读(206)  评论(0编辑  收藏  举报