(function($){ $.fn.eKingScroll = function(options){ var defaults={ direction :"left", //方向 "left" or "top" autoScroll :true //是否开启自动滚动,"true" or "false" }; var options = $.extend(defaults,options); var oSlider=$(this); var ad_box = $(this).find('[data-role="ad_box"]'); var len = $(this).find('[data-role="ad_box"]').find("li").length -1; var ad_num = $(this).find('[data-role="ad_num"]'); var index = 0; var adTimer,mantual=false; oSlider.find('[data-role="ad_num"]').find("li:first").addClass("on"); ad_num.find("li").hover(function(){ mantual=true; index = ad_num.find("li").index(this); showImg(index); },function(){ mantual=false; }); //是否开启自动滚动 if(options.autoScroll){ adTimer = setInterval(function(){ if(!mantual){ if(index==len){ index =0; }else{ index++; } showImg(index); } } , 5000); }; oSlider.hover(function(){ mantual=true; },function(){ mantual=false; }); function showImg(index){ if(options.direction =="left"){ var adWidth =oSlider.find('[data-role="ad_pannel"]').width(); oSlider.find('[data-role="ad_box"]').stop(true,false).animate({left : -adWidth*index},600); } else{ var adHeight =oSlider.find('[data-role="ad_pannel"]').height(); oSlider.find('[data-role="ad_box"]').stop(true,false).animate({top : -adHeight*index},600); } ad_num.find("li").removeClass("on").eq(index).addClass("on"); } }})(jQuery);