简体   繁体   中英

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.

Here, all is ok because there are enough content: 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)

How can i fix it so the affix div stays static and not fixed when there is no enough content?

Thank you

Using jquery, get the height of the document, less the header and footer heights. Then use this to put an if statement on the affix.

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/

Remove position absolute from .affix-bottom

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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