【问题标题】:position: fixed not referring parent relative left position位置:固定不参考父相对左侧位置
【发布时间】:2011-04-03 15:40:28
【问题描述】:

我做了一个例子:向下滚动时,当滚动条到达 RHS 面板标题时,RHS 面板浮动。

http://www.elankeeran.com/test/RHSpanel.htm

但是当向下滚动 RHS 面板时会跳到屏幕外;我不知道为什么位置固定而不是指左父相对位置。它指的是身体左侧的位置。

在css下面更改后工作正常

#floating-box{position: absolute;width:100%;width:960px; margin:0 auto;}

如果有人知道更好的解决方案,请告诉我。

【问题讨论】:

  • 使用绝对位置而不是固定位置,因为固定是指窗口屏幕

标签: javascript jquery html css


【解决方案1】:

既然你问为什么会发生这种情况,请参阅the CSS specposition : fixed 的定义,特别是

对于一个固定定位的盒子,包含块是由 视口。

或者,正如another site 所说,

the parent element is always the browser window

【讨论】:

    【解决方案2】:
    var wHeight = $(window).height();
    $('.right-panel').css("height",wHeight-80);
    if ( scrollY > bodyY && isfixed ) {
     $floatingbox.stop().css({
    position: 'fixed',
        // left: wLeft,
    top: 10
    

    移除 !isfixed 并使其变为 isfixed

    【讨论】:

    • @elankeeran 你会详细说明因为它有效我复制了你的代码并尝试了!
    • var isfixed = $floatingbox.css('position') == 'fixed';你的 isfixed 设置为 fixed 因此 if 块永远不会工作..这就是问题所在..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-17
    • 2013-08-11
    • 2023-04-02
    • 2018-10-06
    • 2018-03-24
    • 1970-01-01
    相关资源
    最近更新 更多