1

我的理解position: absolute是对于具有非静态职位的第一个父母来说是绝对的。如果没有父级有指定的位置,那么它将是浏览器/窗口的绝对位置。

position: fixed另一方面,对于浏览器来说是绝对的,但是如果处于 quirks 模式,它对 IE 不起作用。

我的问题是我想要一些东西,top:0; left:0;但网站处于怪癖模式,我只在我的个人 div 中进行编辑。(这是一个类似 myspace 的用户网站)。有许多父 div 具有position: relative.

我怎样才能在不需要物体静止的情况下表现position: absolute得像position: fixed(如果需要它可以是静止的)?

4

1 回答 1

1

早期版本的 IE 只是不支持 position: fixed;

我唯一知道的是一个 javacript 解决方法,如下所示:

var layerPadding = 5;
function layerScrollFixEx() {
    if (layerGetScrollPosition() != (document.getElementById('layer').offsetTop - layerPadding)) {
        document.getElementById('layer').style.top = layerGetScrollPosition() + layerPadding + "px";
    }
}

function layerGetScrollPosition() {
    if (typeof window.pageYOffset != 'undefined') {
         return window.pageYOffset;
    }
    else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') {
         return document.documentElement.scrollTop;
    }
        else if (typeof document.body != 'undefined') {
         return document.body.scrollTop;
    }
}
layerScrollInterval = window.setInterval("layerScrollFixEx()", 1);

这是一些代码的摘录,当这仍然相关时,我做了一段时间。

于 2010-12-12T11:21:40.017 回答