我做过一个例子:向下滚动时,当滚动条到达 RHS 面板标题时,RHS 面板 float 。
http://www.elankeeran.com/test/RHSpanel.htm
但是向下滚动 RHS 面板时会跳转到屏幕外;我不明白为什么 position fixed 不是指父相对位置。它指的是 body 的左侧位置。
在 css 下更改后它工作正常
#floating-box{position: absolute;width:100%;width:960px; margin:0 auto;}
如果有人知道更好的解决方案,请告诉我。
最佳答案
既然你问过为什么会发生这种情况,请参阅 the CSS spec 中 position : fixed
的定义, 值得注意的是
for a fixed positioned box, the containing block is established by the viewport.
或者,作为 another site把它,
the parent element is always the browser window
关于javascript - 位置 : fixed not referring parent relative left position,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5530578/