简体   繁体   English

固定位置窗口滚动问题

[英]Fixed Position window scrolling issue

So I have a page layout that has a main content container div that is position relative. 因此,我有一个页面布局,该页面布局具有相对位置的主要内容容器div。 With in this container I have two other layout divs, one acting as a side bar the other acting as a content container that can scroll up and down. 在这个容器中,我还有另外两个布局div,一个作为侧边栏,另一个作为可以上下滚动的内容容器。 This div also has a heading bar that must remain in place when you scroll through this div. 该div上还有一个标题栏,当您在该div上滚动时,该标题栏必须保持在原位。 If I fix the position the heading bar it will stay in place with out a problem as long as you scroll with in that container. 如果我固定了标题栏的位置,那么只要您在该容器中滚动,标题栏就不会出现问题。 If you scroll the entire window though (outside the wrapper div) the header bar scrolls along with it. 如果滚动整个窗口(在包装div之外),则标题栏也会随之滚动。 I know why this is happening but would like to know if there is a way to fix it or prevent this behavior. 我知道为什么会发生这种情况,但想知道是否有办法解决或防止这种情况。 I do not mind using Javascript to do so either. 我也不介意使用Javascript来这样做。 I understand that that fixed positioning only makes the element fixed to its parent container. 我知道固定位置只会使元素固定到其父容器。

This is most likely hard to understand at least lay out wise through just text so here is a very simple example fiddle of just some mark up showing which items are fixed and how they are sort of laid out. 至少仅通过文本就很难理解这一点,因此,这是一个非常简单的示例,其中仅显示一些标记,显示哪些项目是固定的,以及它们如何进行布局。 http://jsfiddle.net/gvNqv/ http://jsfiddle.net/gvNqv/

Thanks a bunch for any possible help with this! 多谢您为此提供任何可能的帮助!

EDIT: Adding code from fiddle here 编辑:从小提琴这里添加代码

.maincontent{ 
    position:relative; 
    width:760px;
}
.sidebar{
    float:left;
}
.stage{
    float:right;
    position:relative;
}
.headbar{
    position:fixed;
}

<div class="wrapper">
   <div class="mainContent">

      <div class="sideBar"></div>

      <div class="stage">
         <div class="headbar">banner text</div>        
      </div>

   </div>
</div>​

enter code here

您是否不需要使用顶部,左侧,底部或右侧将其固定在某个物体上?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM