My goal is to develop a sticky menu utilizing CSS Bootstrap affix and the list-group
menu.
I have successfully implemented most of it, except for one issue when the user scrolls down.
Upon scrolling down, the menu expands to fill the entire width of the page.
I attempted to set it up using data attributes like so:
Here is an example of my code:
<div class="container">
<div class="row">
<div class="col-md-3" id="leftCol">
<div data-spy="affix">
<div class="list-group list-group-root well">
<a class="list-group-item" href="#introduction">Introduction</a>
<a class="list-group-item" href="#features">Features</a>
<a class="list-group-item" href="#dependencies">Dependencies</a>
</div>
</div>
</div>
<div class="col-md-9" id="mainCol">
Some lengthy content for the body along with tables.
</div>
</div>
</div>
However, the data attribute did not achieve the desired sticky effect; instead, it remained fixed at the top.
To address this issue, I tried incorporating JavaScript to fix the problem:
$(function(){
$('#leftCol').affix({
offset: {
top: 100,
bottom: function () {
return (this.bottom = $('.footer').outerHeight(true))
}
}
});
});
I have included a jsFiddle link to showcase the current behavior.
What steps can I take to ensure that the affix
functionality maintains the menu's shape as the user scrolls down?