简体   繁体   English

当词缀div大于内容和窗口时,附带引导程序的问题

[英]Issue with affix bootstrap when the affix div is bigger than content and the window

I have a an issue with affix bootstrap, when the affix div is bigger than the main content and the window. 当词缀div大于主要内容和窗口时,我有一个关于词缀引导程序的问题。

Here, all is ok because there are enough content: http://jsfiddle.net/d8jzenbr/ 在这里,一切都很好,因为有足够的内容: http//jsfiddle.net/d8jzenbr/

var headerHeight = $('header').outerHeight(true); /
var footerHeight = $('footer').outerHeight() + 60;
$('#account-overview-container').affix({
    offset: {
        top: headerHeight,
        bottom: footerHeight
    }
}).on('affix.bs.affix', function () { // before affix
});

See the issue here, when the content isn't big enough: http://jsfiddle.net/90m0r91t/ (there is an issue when affix-top becomes affix) 当内容不够大时,请看这里的问题: http//jsfiddle.net/90m0r91t/ (当affix-top成为词缀时出现问题)

How can i fix it so the affix div stays static and not fixed when there is no enough content? 我怎么能修复它所以当没有足够的内容时,词缀div保持静态而不是固定?

Thank you 谢谢

Using jquery, get the height of the document, less the header and footer heights. 使用jquery,获取文档的高度,减去页眉和页脚的高度。 Then use this to put an if statement on the affix. 然后使用它在词缀上加上if语句。

if(contentHeight > sidebarHeight) {
  $('#account-overview-container').affix({
      offset: {
          top: headerHeight,
          bottom: footerHeight
      }
  }).on('affix.bs.affix', function () { // before affix
      $(this).css({
          /*'top': headerHeight,*/    // for fixed height
      });
  })
}

DEMO: http://jsfiddle.net/d8jzenbr/6/ 演示: http//jsfiddle.net/d8jzenbr/6/

Remove position absolute from .affix-bottom .affix-bottom删除绝对位置

.affix-bottom{
position:absolute /* Comment out this line */
}

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

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