Skip to content
Advertisement

Bootstrap – sticky navbar, sticky sidebars (left and right) with dynamic content as you scroll

I’m trying to make a bootstrap layout with a sticky navbar and sticky sidebars (exactly like Facebook layout). However, the content needs to change as you scroll the page. I spent a lot of time looking for how to do this with bootstrap, making the facebook-style sticky layout isn’t a problem, but I can’t find any bootstrap example with changing content as you scroll.

Here’s an example of what I need: https://semantic-ui.com/modules/sticky.html#/examples

I’m trying to reproduce the exact same behavior of semantic-ui sticky module, but with bootstrap. The sticky sidebars on the left and right of this page is EXACTLY what I need (just missing the top navbar)… but how can I do this with bootstrap instead of semantic-ui?

THANKS!

Advertisement

Answer

You can do this using the jQuery Sticky library. Include the script on your page and call it a following.

JavaScript

Here’s a working example.

JavaScript
JavaScript
JavaScript

You can set various settings, in your case the topSpacing and bottomSpacing are needed to make a sidebar item stick for a certain period and then scroll off the page. To make sure the sidebars don’t appear on top of the navigation bar, set the zIndex property of each item accordingly. Here’s a JSFiddle which brings a visual to this paragraph.

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement