简体   繁体   English

在页面的左侧和右侧都贴有Bootstrap

[英]Bootstrap affix in both left and right side of the page

This is how my page is structured. 这是我的页面的结构。 Left column (col-lg-3) Center Column (col-lg-6) Right column (col-lg-3) 左列(col-lg-3)中心列(col-lg-6)右列(col-lg-3)

While my main content would be in center column, I want my left column and right column to be fixed (or sticky ) after certain scroll position. 虽然我的主要内容将位于中间列,但我希望在某些滚动位置之后将我的左列和右列固定(或粘滞)。

Most of the solutions I found in the internet was with 1 left column to be sticky. 我在互联网上发现的大多数解决方案都带有1个左列。 I think there's something javascript works needs to be done. 我认为需要完成一些javascript工作。

Please visit http://www.bootply.com/LiOE57ZlwI . 请访问http://www.bootply.com/LiOE57ZlwI So far left column is working exactly the way I want it to be..and I want right column to behave same as left column. 到目前为止,左列的工作方式完全符合我的要求。我希望右列的行为与左列相同。

Also please visit http://www.bootply.com/101100 . 另外,请访问http://www.bootply.com/101100 I want the exact same behavior. 我想要完全一样的行为。 I don't want to use this code because it's all messed up in low screen size. 我不想使用此代码,因为它们在低屏幕尺寸中都被弄乱了。

Thanks 谢谢

Instead of using an id, use a class: 代替使用id,使用一个类:

/* activate sidebar */
$('.sidebar').affix({
  offset: {
    top: 235
  }
});

and in html, don't use id and put "sidebar" in a class 并且在html中,请勿使用id并将“侧边栏”放在类中

<div class="col-md-3" id="leftCol">
    <ul class="nav nav-stacked sidebar">
      <li><a href="#sec0">Section 0</a></li>
      <li><a href="#sec1">Section 1</a></li>
      <li><a href="#sec2">Section 2</a></li>
      <li><a href="#sec3">Section 3</a></li>
      <li><a href="#sec4">Section 4</a></li>
    </ul>
</div><!--/left-->
<div class="col-md-3" id="leftCol">
    <ul class="nav nav-stacked sidebar">
      <li><a href="#sec0">Section 0</a></li>
      <li><a href="#sec1">Section 1</a></li>
      <li><a href="#sec2">Section 2</a></li>
      <li><a href="#sec3">Section 3</a></li>
      <li><a href="#sec4">Section 4</a></li>
    </ul>
</div><!--/right-->

and css change to class as well: 和CSS也更改为class:

@media (min-width: 979px) {
  .sidebar.affix-top {
    position: static;
    margin-top:30px;
    width:228px;
  }

  .sidebar.affix {
    position: fixed;
    top:70px;
    width:228px;
  }
}

.sidebar li.active {
  border:0 #eee solid;
  border-right-width:5px;
}

Demo here 在这里演示

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

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