html首行冻结固定完整实例

<?php
header("Content-type:text/html;charset=utf-8");  
error_reporting(0);
session_start();
include("conn.php");
?>
<!DOCTYPE html>
<html>
<head>
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta charset="utf-8">
	<title></title>
	<link rel="stylesheet" href="bootstrap.min.css">
	<script src="jquery.min.js"></script>
	<script src="bootstrap.min.js"></script>
</head>
<style type="text/css">
td{
	text-decoration:none;
}
#tScroll{
	position:fixed;
	top:0;
	display:none;
}
</style>
<body>
	<script>
		$(document).ready(function () {
			var $tmain = $("#tMain");
			var $tScroll = $("#tScroll");
			var pos = $tmain.offset().top + $tmain.find(">thead").height();
			$(document).scroll(function () {
				var dataScroll = $tScroll.data("scroll");
				dataScroll = dataScroll || false;
				if ($(this).scrollTop() >= pos) {
					if (!dataScroll) {
						$tScroll
						.data("scroll", true)
						.show()
						.find("th").each(function () {
							$(this).width($tmain.find(">thead>tr>th").eq($(this).index()).width());
						})
						;
					}
				} else {
					if (dataScroll) {
						$tScroll
						.data("scroll", false)
						.hide()
						;
					}
				}
			});
		});
	</script>

	<table id="tScroll" width="100%" class="table table-bordered" style="background-color:#ffffff">
		<thead>
			<tr>
				<th>项目1</th>
				<th>项目2</th>
				<th>项目3</th>
				
			</tr>
		</thead>
	</table>
	<table width="100%" id="tMain" class="table table-bordered">
		<thead>
			<tr>
				<th>项目1</th>
				<th>项目2</th>
				<th>项目3</th>
			</tr>
		</thead>
		<?php
		$sql="SELECT * from intd order by id desc";
		$xuhao=1;
		$rs=mysql_query($sql);
		while($rows=mysql_fetch_array($rs)){
			?>
			<tr <?php 
			if ($xuhao%2!=0) {
				?>
				class="info"
				<?php } ?>  >
				<td><?php echo $rows["xm1"]?></td>
				<td><?php echo $rows["xm2"]?></td>
				<td><?php echo $rows["xm3"]?></td>
			</tr>
			<?php
			$xuhao++;
		}
		?>
	</table>
</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值