我有一个固定的 div 并希望保持它固定,这样当它的父级滚动时它保持原样但是当父级的滚动完成并且当主体滚动开始时“有问题的容器”应该开始滚动.
有点像
<div id="fixedContainer">container in question</div>
#fixedContainer
{
background-color:#ddd;
position: fixed;
width: 200px;
height: 100px;
left: 50%;
top: 0%;
margin-left: -100px; /*half the width*/
}
然后
<div style="height:300px;background-color:#bbb;overflow:scroll;">soeme div</div>
我在这里做了一个示例 http://jsfiddle.net/tDpJB/
在此先感谢您的帮助。 -拉维。
最佳答案
将元素绝对定位在滚动容器上方而不是试图将其固定在内部不是更好的主意吗?这会模拟您正在寻找的效果吗?
关于javascript - 当直接父级滚动时使容器固定但当主体滚动时不固定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15096363/