Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap: Stop affix when reaching end of certain div

I have a sidebar thats sticks when you scroll. Now I want it to stop (and be fixed) when reaching a certain div.

For illustration. What happends: http://postimg.org/image/l1n0djb0n/

What I want: http://postimg.org/image/5evr05x8n/

I needs to stop floating (on scroll) when reaching the bottom of the last content.

How can I do this?

CSS:

#sidebar.affix-top {
position: static;
margin-top:0px; 
}

#sidebar.affix {
position: fixed;
top:49px;
}

HTML:

 <div id="sidebar" class="sidebar_package">
 info for sidebar

 <div class="hiddenpackage_c2a">
     more content
 </div>

 </div>

JS:

//Side menu floater
$('#sidebar').affix({
      offset: {
        //top: $('header').height()
        top:185
      }
});
like image 381
Pieter hein Avatar asked Aug 07 '15 15:08

Pieter hein


1 Answers

You can use the bottom offset

$('#sidebar').affix({
    offset: {
       top: 180,
       bottom: $('#bottom-div').outerHeight(true)
   }
});

And add the following css

.affix-bottom { 
    position: absolute; 
}
like image 62
Kaushtuv Avatar answered Sep 25 '22 17:09

Kaushtuv