Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter Bootstrap Affix - how to stick to bottom?

Tags:

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.


DEMO: http://jsfiddle.net/uvnGP/1/

JS

$("#account-overview-container").affix({
    offset: {
        top: $("header").outerHeight(true),
        bottom: $("footer").outerHeight(true)
    }
});

SASS

#account-overview-container {
    &.affix{
        top:10px;
        bottom:auto;
    }

    &.affix-top{
        //Do I need this?
    }

    &.affix-bottom{
        position:absolute;
        top:auto;
        bottom:140px;
    }
}
like image 877
FiniteLooper Avatar asked Mar 05 '13 15:03

FiniteLooper


People also ask

What is the bootstrap affix plugin?

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.

How to add sticky position in Bootstrap 4?

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.

How to set bootstrap scroll to the bottom of long sticky sidebar?

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.

What is Twitter Bootstrap?

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.


1 Answers

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
});
like image 190
Paco Rivera Avatar answered Sep 24 '22 07:09

Paco Rivera