简体   繁体   English

Bootstrap'Affix'不会贴在右侧

[英]Bootstrap 'Affix' wont affix on the right

I've created an example here : http://jsfiddle.net/Ninjanoel/9GEGU/ 我在这里创建了一个例子: http//jsfiddle.net/Ninjanoel/9GEGU/

Basically, I'd like to affix something to the right, in this case, the red box, I want it to appear to just pin itself to the top as it should once the correct amount of page scroll has occurred, but everytime it 'affixes', it jumps to the left, overlapping the content I already have on the left. 基本上,我想在右侧添加一些东西,在这种情况下,红色框,我希望它看起来只是将自己固定在顶部,因为它应该在正确的页面滚动量发生后,但每次都是'词缀',它跳到左边,重叠我已经在左边的内容。

It's great that bootstrap has such a volume of documentation, but unfortunately I think I'm missing something regarding this. 引导程序有如此大量的文档是很棒的,但不幸的是我觉得我对此缺少了一些东西。 Please help. 请帮忙。

var offsetFn = function() {
   return $('#sidebar').position().top;
}

$(document).ready(function(e) {
  $('#sidebar').affix({
      offset: {top: offsetFn}
  });
});​

is a code snippet I found on Stack overflow to not have to guess the top offset value, but even if I give it a simple value, when the div becomes affixed it jumps left. 是我在堆栈溢出时发现的代码片段,不必猜测顶部偏移值,但即使我给它一个简单的值,当div加入时它会向左跳跃。

Note about the fiddle : it doesn't appear to be working very well, at least the version on my hdd jumps left, but it is the code i'm using basically, and the small window size may complicate things, green and red boxes are suppose to be vertical columns 关于小提琴的注意事项 :它似乎不能很好地工作,至少我的硬盘上的版本向左跳,但它是我基本上使用的代码,小窗口大小可能使事情变得复杂,绿色和红色框假设是垂直列

Create inner div for sidebar. 为侧边栏创建内部div。 Affix is setting position: fixed to column therefore making it not working. 贴子是设置position: fixed到列因此使其不起作用。

Edit: see http://jsfiddle.net/9GEGU/2/ and your function is needless, only causing weird behaviour in FF, so remove {offset: {top: offsetFn}} . 编辑:请参阅http://jsfiddle.net/9GEGU/2/并且您的函数是不必要的,只会导致FF中出现奇怪的行为,因此请删除{offset: {top: offsetFn}} It will look the same but scrolling will be smoother. 它看起来会一样但滚动会更顺畅。

Also set width of span5 (290px) to the #sidebar because when element has position: fixed it is removed from document flow and isn't limited by parent's width. 还要将span5(290px)的宽度设置为#sidebar,因为当element具有position: fixed它将从文档流中删除,并且不受父级宽度的限制。

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

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