用js实现table内容从下到上连续滚动
网上有很多用ul实现新闻列表滚动的例子,但是很少有直接用table实现列表内容滚动的例子,而Marquee标签滚动的效果不是很好,于是就自己写了一个,提供给攻城师朋友们参考
实现思路:由于table包含标题和内容,实际上理想的效果是标题不动,内容滚动,于是把标题和内容拆分出来放在两个table中
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<title>table内容连续滚动</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
* {padding: 0; margin: 0};
td {height: 28px;};
</style>
</head>
<body bgcolor="#FFFFFF">
<div style="padding-top: 100px;">
<table width="600" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="4FBFF9">
<tr>
<td width="120" align="center">业务流水号</td>
<td width="130" align="center">业务名称</td>
<td width="150" align="center">申请企业名称</td>
<td width="100" align="center">申报日期</td>
<td width="100" align="center">办理状态</td>
</tr>
</table>
</div>
<div id="demo" style="overflow: hidden; height: 240;">
<div id="demo1">
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="4FBFF9">
<tr>
<td width="120" align="center">201404020001</td>
<td width="130">测试业务</td>
<td width="150">申请企业名称</td>
<td width="100" align="center">2014-03-13</td>
<td width="100" align="center">在办</td>
</tr>
<tr>
<td align="center">201404020002</td>
<td>测试业务</td>
<td>申请企业名称</td>
<td align="center">2014-03-13</td>
<td align="center">在办</td>
</tr>
<tr>
<td align="center">201404020003</td>
<td>测试业务</td>
<td>申请企业名称</td>
<td align="center">2014-03-13</td>
<td align="center">在办</td>
</tr>
<tr>
<td align="center">201404020004</td>
<td>测试业务</td>
<td>申请企业名称</td>
<td align="center">2014-03-13</td>
<td align="center">在办</td>
</tr>
<tr>
<td align="center">201404020005</td>
<td>测试业务</td>
<td>申请企业名称</td>
<td align="center">2014-03-13</td>
<td align="center">在办</td>
</tr>
<tr>
<td align="center">201404020006</td>
<td>测试业务</td>
<td>申请企业名称</td>
<td align="center">2014-03-13</td>
<td align="center">在办</td>
</tr>
<tr>
<td align="center">201404020007</td>
<td>测试业务</td>
<td>申请企业名称</td>
<td align="center">2014-03-13</td>
<td align="center">在办</td>
</tr>
<tr>
<td align="center">201404020008</td>
<td>测试业务</td>
<td>申请企业名称</td>
<td align="center">2014-03-13</td>
<td align="center">在办</td>
</tr>
<tr>
<td align="center">201404020009</td>
<td>测试业务</td>
<td>申请企业名称</td>
<td align="center">2014-03-13</td>
<td align="center">在办</td>
</tr>
<tr>
<td align="center">201404020010</td>
<td>测试业务</td>
<td>申请企业名称</td>
<td align="center">2014-03-13</td>
<td align="center">在办</td>
</tr>
<tr>
<td align="center">201404020011</td>
<td>测试业务</td>
<td>申请企业名称</td>
<td align="center">2014-03-13</td>
<td align="center">在办</td>
</tr>
<tr>
<td align="center">201404020012</td>
<td>测试业务</td>
<td>申请企业名称</td>
<td align="center">2014-03-13</td>
<td align="center">在办</td>
</tr>
<tr>
<td align="center">201404020013</td>
<td>测试业务</td>
<td>申请企业名称</td>
<td align="center">2014-03-13</td>
<td align="center">在办</td>
</tr>
<tr>
<td align="center">201404020014</td>
<td>测试业务</td>
<td>申请企业名称</td>
<td align="center">2014-03-13</td>
<td align="center">在办</td>
</tr>
<tr>
<td align="center">201404020015</td>
<td>测试业务</td>
<td>申请企业名称</td>
<td align="center">2014-03-13</td>
<td align="center">在办</td>
</tr>
<tr>
<td align="center">201404020016</td>
<td>测试业务</td>
<td>申请企业名称</td>
<td align="center">2014-03-13</td>
<td align="center">在办</td>
</tr>
<tr>
<td align="center">201404020017</td>
<td>测试业务</td>
<td>申请企业名称</td>
<td align="center">2014-03-13</td>
<td align="center">在办</td>
</tr>
<tr>
<td align="center">201404020018</td>
<td>测试业务</td>
<td>申请企业名称</td>
<td align="center">2014-03-13</td>
<td align="center">在办</td>
</tr>
<tr>
<td align="center">201404020019</td>
<td>测试业务</td>
<td>申请企业名称</td>
<td align="center">2014-03-13</td>
<td align="center">在办</td>
</tr>
<tr>
<td align="center">201404020020</td>
<td>测试业务</td>
<td>申请企业名称</td>
<td align="center">2014-03-13</td>
<td align="center">在办</td>
</tr>
</table>
</div>
<div id="demo2"></div>
</div>
<script type="text/javascript">
var speed = 50;
demo2.innerHTML = demo1.innerHTML;
function Marquee() {
if (demo2.offsetTop - demo.scrollTop <= 0) {
demo.scrollTop -= demo1.offsetHeight;
} else {
demo.scrollTop++;
}
}
var MyMar = setInterval(Marquee, speed);
demo.onmouseover = function() {
clearInterval(MyMar);
}
demo.onmouseout = function() {
MyMar = setInterval(Marquee, speed);
}
</script>
</body>
</html>
原文链接https://www.cnblogs.com/wenlong/p/3684226.html