I've read the documentation, and I feel like I'm doing exactly what they show in their examples. Yet when I try it, I can't get this to work. I'd like it to work in a way similar to the docs. It becomes position:fixed
after scrolling past the header, and then once it touches the footer it becomes position:absolute
and sticks to the bottom.
$("#account-overview-container").affix({
offset: {
top: $("header").outerHeight(true),
bottom: $("footer").outerHeight(true)
}
});
#account-overview-container {
&.affix{
top:10px;
bottom:auto;
}
&.affix-top{
//Do I need this?
}
&.affix-bottom{
position:absolute;
top:auto;
bottom:140px;
}
}
Bootstrap Affix Plugin (Advanced) ❮ Previous Next ❯. The Affix plugin allows an element to become affixed (locked) to an area on the page. This is often used with navigation menus or social icon buttons, to make them "stick" at a specific area while scrolling up and down the page.
To achieve this affix property as like as Bootstrap 3, Bootstrap 4 recommends us CSS property i.e., position: sticky; directly in style or implementing position:sticky; on @supports rule. Though the position:sticky might not support in all cases, we can adopt the third-party ScrollPos-Styler library.
In Bootstrap 3, to set bootstrap scroll to the bottom of long sticky sidebar is possible using Affix which is handled by “Affix jQuery plugin”. Unfortunately, in Bootstrap 4 migration “Affix jQuery plugin” was dropped.
Objective. Twitter Bootstrap is a front end framework to develop web apps and sites fast. In modern web development, there are several components which are required in almost all web projects. Bootstrap provides you with all those basic modules - Grid, Typography, Tables, Forms, Buttons, and Responsiveness.
There some changes from your code but the solution fits for variable header and footer height, responsive width and can be change for fixed header.
Here is the link
http://jsfiddle.net/uvnGP/131/
The problem was, when the affix hit the bottom, there was a top and a bottom css style added to your container (#sidebar), the way to fix it is to reset that bottom style to auto, that way only the top style will acto on your container
here is the code:
var headerHeight = $('header').outerHeight(true); // true value, adds margins to the total height
var footerHeight = $('footer').innerHeight();
$('#account-overview-container').affix({
offset: {
top: headerHeight,
bottom: footerHeight
}
}).on('affix.bs.affix', function () { // before affix
$(this).css({
/*'top': headerHeight,*/ // for fixed height
'width': $(this).outerWidth() // variable widths
});
}).on('affix-bottom.bs.affix', function () { // before affix-bottom
$(this).css('bottom', 'auto'); // THIS is what makes the jumping
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With