Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 容器溢出时的浮动表标题?_Javascript_Css_Prototypejs - Fatal编程技术网

Javascript 容器溢出时的浮动表标题?

Javascript 容器溢出时的浮动表标题?,javascript,css,prototypejs,Javascript,Css,Prototypejs,我正在使用position:fixed在用户滚动过顶部时浮动表格中的一些标题,如下方法: 在常规页面上,一切都很好,但每当我在另一个div或其他具有固定高度的内容中有一个表,并且overflow:auto时,它就会爆炸得惊人 我需要做些什么来解释页面范围的滚动,以及容器的滚动?以及滚动超过所述容器的“顶部”的原因 谢谢你们给我指点方向 以下是我现有的代码: var mainheader = table.rows[0]; var tableHeight = table.getHeight(); v

我正在使用
position:fixed
在用户滚动过顶部时浮动表格中的一些标题,如下方法:

在常规页面上,一切都很好,但每当我在另一个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';
var mainheader=table.rows[0];
var tableHeight=table.getHeight();
var tableScroll=table.viewportOffset();
var headerHeight=mainheader.getHeight();
//TODO:如果我们滚动一个子容器,我们也需要得到它的偏移量!以某种方式
//如果tableHeight<1,则表示我们的桌子现在处于隐藏状态,因此跳过它
if(桌高<1)
继续;
//如果我们已经向下滚动过了表的顶部,但还没有滚动到表的末尾,那么显示我们的浮动标题
if(tableScroll.top<0&&tableHeight+tableScroll.top-床头高度>0)
{
table.floatingheader.style.display='';
//处理水平滚动也!
table.floatingheader.style.left=(tableScroll.left+1)+“px”;//边框的1px偏移量
}
其他的
table.floatingheader.style.display='none';

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

我知道您没有使用jQuery,但您可能想看看github上的这段代码,看看他是如何实现的,然后根据您的需要修改它:

这正是我需要的。谢谢