0

当用户滚动到顶部时,我使用position:fixed在我的表格中浮动一些标题,ala 这种方法:http ://css-tricks.com/persistent-headers/

在常规页面上一切都很好,但是每当我在另一个 div 内有一张桌子或具有固定高度的东西时,overflow:auto它就会爆炸。

我需要做什么来不仅考虑页面范围的滚动,还考虑容器的滚动?并考虑滚动超过所述容器的“顶部”?

感谢你们可以指出我的任何方向。

这是我现有的代码:

var mainheader = table.rows[0];
var tableHeight = table.getHeight();
var tableScroll = table.viewportOffset();
var headerHeight = mainheader.getHeight();

// TODO: If we're scrolling a subcontainer, we need to get the offset for that too! Somehow?

// If tableHeight < 1, it means our table his hidden right now, so skip it
if (tableHeight < 1)
    continue;

// If we've scroll down past the very tip top of the table, but haven't yet scroll past the end of it, show our floating headers
if (tableScroll.top < 0 && tableHeight + tableScroll.top - headerHeight > 0)
{
    table.floatingheader.style.display = '';

    // Handle horizontal scrolling too!
    table.floatingheader.style.left = (tableScroll.left + 1) + 'px'; // 1px offset for border
}
else
    table.floatingheader.style.display = 'none';

注意:我可以访问prototype.js,但没有jQuery 或任何其他第三方库。:/

4

1 回答 1

1

I realize you're not using jQuery but you may want to look at this guys code on github and see how he implements it, then modify it for your purposes: http://webpop.github.com/jquery.pin/

于 2013-03-29T20:53:55.987 回答