我试过做固定滚动标题。在此过程中,尝试修复HEAD表位置固定。我做的。但是,当我滚动表格时,HEAD表格正在闪烁。它在Firefox中没有闪烁。我不想在IE,Chrome或任何浏览器中出现这种情况。任何帮助都将受到高度赞赏。
CSS代码:
<style type="text/css">
th {
background:#663300;
color:#FFF;}
</style>
JQUERY CODE
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#mainDiv").scroll(function() {
var offSet = $("#mainDiv").offset().top;
$("#headTable").offset({"top":offSet});
});
});
</script>
HTML代码(完整页面代码)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
th {
background:#663300;
color:#FFF;}
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#mainDiv").scroll(function() {
var offSet = $("#mainDiv").offset().top;
$("#headTable").offset({"top":offSet});
});
});
</script>
</head>
<body>
<p style="height:100px;"> </p>
<div id="mainDiv" style="border:1px solid red; width:400px; height:100px; overflow:auto; position:relative;">
<table id="headTable" border="0" cellpadding="0" cellspacing="0" width="600" style="z-index:10;">
<tr>
<th>asdf</th>
<th>asdf</th>
<th>asdf</th>
<th>asdf</th>
<th>asdf</th>
<th>asdf</th>
<th>asdf</th>
<th>asdf</th>
<th>asdf</th>
<th>asdf</th>
<th>asdf</th>
<th>asdf</th>
<th>asdf</th>
</tr>
</table>
<table id="bodyTable" border="0" cellpadding="0" cellspacing="0" width="600" style="z-index:9;">
<tr>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
</tr>
<tr>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
</tr>
<tr>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
</tr>
<tr>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
</tr>
<tr>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
</tr>
<tr>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
</tr>
<tr>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
</tr>
<tr>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
</tr>
<tr>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
</tr>
<tr>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
</tr>
<tr>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
</tr>
<tr>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
</tr>
<tr>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
</tr>
<tr>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
</tr>
<tr>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
</tr>
<tr>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
</tr>
<tr>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
</tr>
<tr>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
</tr>
<tr>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
</tr>
<tr>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
<td>asdf</td>
</tr>
</table>
</div>
</body>
</html>
答案 0 :(得分:0)
因为onscroll很慢并且不能提供使其平滑所需的精度。无需使用onscroll设置标头,CSS将标头表放置在可滚动div的顶部。