最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Bootstrap 'Affix' wont affix on the right - Stack Overflow

programmeradmin0浏览0评论

I've created an example here : /

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 bees affixed it jumps left.

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 plicate things, green and red boxes are suppose to be vertical columns

I've created an example here : http://jsfiddle/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 bees affixed it jumps left.

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 plicate things, green and red boxes are suppose to be vertical columns

Share Improve this question edited Dec 2, 2012 at 23:44 Ninjanoel asked Dec 2, 2012 at 23:39 NinjanoelNinjanoel 2,9147 gold badges35 silver badges53 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

Create inner div for sidebar. Affix is setting position: fixed to column therefore making it not working.

Edit: see http://jsfiddle/9GEGU/2/ and your function is needless, only causing weird behaviour in FF, so remove {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.

发布评论

评论列表(0)

  1. 暂无评论