(function($){ $.fn.extend({ Scroll:function(opt,callback){ //参数初始化 if(!opt) var opt={}; var timerID; var _this=$(this); if(!_this){ return; } var lineH=_this.find("ul:eq(0)").height()+parseInt(_this.css("padding").substring(0,1)); var line=opt.line?parseInt(opt.line,10):parseInt(this.height()/lineH,10); var speed=opt.speed?parseInt(opt.speed,10):500; var timer=opt.timer?parseInt(opt.timer,10):3000; if(line==0) line=1; var upHeight=0-line*lineH; //滚动函数 scrollUp=function(){ _this.animate({ marginTop:upHeight }, speed, function(){ for(i=1;i<=line;i++){ _this.find("ul:first").appendTo(_this); } _this.css({marginTop:0}); }); } //鼠标事件绑定 _this.hover(function(){ //update 刘成武 //clearInterval只能停止方法不再继续执行,不能停止最后一次调用的方法的动画效果 //如果要立即停止,33行代码不要注掉 _this.stop();//鼠标滑进立即停止动画效果 clearInterval(timerID);//clear设置的timerID },function(){ if(timerID){//如果timerID没有clear掉,必须先clear载set。否则效果会加倍 clearInterval(timerID); } scrollUp();//鼠标移出后立即恢复动画效果 //timer时间后开始执行 timerID=setInterval(function(){ scrollUp(); },timer); }); timerID=setInterval(function(){ scrollUp(); },timer); } }) })(jQuery);