我试图做固定的滚动标题。在这个过程中,试图将 HEAD 表的位置固定固定。我做的。但是,当我滚动表格时, HEAD 表格正在闪烁。它在 Firefox 中不闪烁。我不想在 IE、Chrome 或任何浏览器中出现这种闪烁。任何帮助将不胜感激。
代码:
<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>
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>