日期:2014-05-16 浏览次数:20426 次
<table class="class1" id="table1"> <tr><td .../><td .../></tr> <tr><td .../><td .../></tr> <tr><td .../><td .../></tr> ... </table>
<script> //从下往上滚 function scroll1(){ var table = document.getElementById("table1").getElementsByTagName("tbody")[0];//$("#table1 > tbody").get(0) var row = table.firstChild; table.removeChild(row); table.appendChild(row); //可以通过ajax去取后面的数据 } //从上往下滚 function scroll2(){ var table = document.getElementById("table1").getElementsByTagName("tbody")[0]; var row = table.lastChild; table.removeChild(row); table.insertBefore(row,table.firstChild); } </script> <table class="class1" id="table1" onmouseover="this.int=window.setInterval('scroll2()',1000)" onmouseout="window.clearInterval(this.int)"> <tr><td>aaa</td><td>aaa</td></tr> <tr><td>bbb</td><td>bbb</td></tr> <tr><td>ccc</td><td>ccc</td></tr> <tr><td>xxx</td><td>xxx</td></tr> <tr><td>yyy</td><td>yyy</td></tr> <tr><td>zzz</td><td>zzz</td></tr> </table>
------解决方案--------------------
<script type="text/javascript" language="javascript">
function Scroll(opt,callback){
scrollBox = $("#table1");
if(!opt) var opt={};
var _this=scrollBox.eq(0).find("tr:first");
var lineH=_this.find("td:first").height(), //获取行高
line=opt.line?parseInt(opt.line,10):parseInt(scrollBox.height()/lineH,10), //每次滚动的行数,默认为一屏,即父容器高度
speed=opt.speed?parseInt(opt.speed,10):5000, //卷动速度,数值越大,速度越慢(毫秒)