When using the sticky class to stick a div, I encountered an issue where it sticks correctly from the top but overlaps the footer at the bottom.
https://i.sstatic.net/28A3A.jpg
Here is the HTML code:
<div class="tab-content">
<div role="tabpanel" class="tab-pane active " id="menu1">
<div class="col-sm-12"><div class="clear"> </div></div>
<!-- LEFT NAV START -->
<div class="col-sm-3" id="sticky-anchor2">
<div class="sticky2">
<span style="color:red"><strong>Menu Group</strong></span>
<ul aria-labelledby="dropdownMenu1">
<?php foreach ($categories as $key => $value) { ?>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="<?php echo $nav_url; ?>#cat_<?php echo str_replace(' ', '_', trim($key)); ?>" class="anchorLink" style="color:#FFF !important;">
<button class="btn btn-danger btn-sm btn-block setlbl" type="button"><?php echo $key; ?></button></a>
</li>
<?php } ?>
</ul>
</div>
This is the jQuery code I am using:
var window_top = $(window).scrollTop();
var div_top2 = $('#sticky-anchor2').offset().top - 100;
if (window_top > div_top2) {
$('.sticky2').addClass('sticky stick');
} else {
$('.sticky2').removeClass('sticky stick');
}
I would like the div to remove the stick class when it is about 150px from the bottom. How can I achieve this?