How to determine the final distance of an element from the footer?

5

In the case in question would be a sidebar, which from a certain height of scrolling the top, receives position: fixed, but as it continues scrolling it is hidden behind the footer of the site. How could I determine that this sidebar from a certain footer distance would stop? (The footer has about 490px).

    
asked by anonymous 03.01.2014 / 12:46

1 answer

4

You can do this:

$(function(){
    $(window).scroll(function(){

    var div = $('#div');
    var space = $(document).height() - (div.offset().top + div.height());

        if(space <= 'quantidade que você quer'){
            div.css('position','relative');
        }    

    });
});

ai within if you adjust the css as you like ...

    
03.01.2014 / 12:49