自动滚动
$(document).ready(function(){ scroll_f(".luck-tip .scroll-box",300); }); //滚动 var scrollIndex = 0; var Timer = null; function scroll_f(obj,time){ clearInterval(Timer); var ul = $(obj).find("ul"); var li = ul.children("li"); var h = li.height(); var index = 0; ul.css("height",h*li.length*2); ul.html(ul.html()+ul.html()); //复制一份当前ul内容 function run(){ if(scrollIndex>=li.length){ ul.css({top:0}); scrollIndex = 1; ul.animate({top:-scrollIndex*h},time); } else{ scrollIndex++; ul.animate({top:-scrollIndex*h},time); } } Timer= setInterval(run,3000); }