2011-04-03 180 views
1

我已经做了一个例子:在向下滚动时,RHS面板在滚动条到达RHS面板标题时浮动。位置:固定不引用父亲相对左位置

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

但同时向下滚动RHS面板跳转到戏外;我不知道为什么职位固定不是指父母的相对位置。它指的是身体左侧的位置。

下面改变CSS其做工精细

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

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

+0

使用绝对位置,而不是固定的,因为固定指窗口画面中的其他 – sandeep 2011-04-03 16:02:35

回答

0
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设定

+0

相同的条件下可用的位置....它不会工作 – Elankeeran 2011-04-03 16:02:44

+0

@ elankeeran会详细说明它的工作原理,我复制了我们的代码并尝试过! – pyth 2011-04-03 16:09:17

+0

var isfixed = $ floatingbox.css('position')=='fixed';你被固定设置为固定的,因此if块永远不会工作..那是什么给了这个问题.. – pyth 2011-04-03 16:11:03

3

既然你问为什么发生这种情况,看到的position : fixed的定义the CSS spec,尤其是

一个固定的定位的盒子,包含块由 视口建立。

或者,如another site所说的那样,

the parent element is always the browser window