我有一个有很多行的表格,这会使页面滚动。桌子上面还有一些其他的内容。我想添加一个使用jQuery的功能,在页面顶部显示div,只要表格滚动到顶行消失在屏幕顶端的地方。
我假设我将添加一个位置设置为fixed的div,但是我如何知道第一行何时移动到fold之上呢?
<div id="topDiv" style="display: none; position: fixed; top: 0"></div>
<table>
<thead>
<tr>
<th></th>
<tr>
</thead>
<tbody>
<tr>
<td></td>
<tr>
...
</tbody>
</table>发布于 2012-04-07 11:18:50
发布于 2012-04-07 11:24:53
您可以使用下面这样的内容
$(window).scroll(function(e){
$el = $('#topDiv');
if ($(this).scrollTop() > 200 && $el.css('position') != 'fixed'){
$el.css({'position': 'fixed', 'top': '0px'});
}
});此检查窗口是否滚动超过200px并修复topDiv
https://stackoverflow.com/questions/10051419
复制相似问题