I found this solution and need to modify it so that when it hits the footer it unsticks. I know there is no scroll_bottom, so I was thinking of trying to create a variable for the footer, like below. I will keep plugging away, however, was hoping maybe someone could help out.
$(document).ready(function() {
// Cache selectors for faster performance.
var $window = $(window),
$mainMenuBar = $('#mainMenuBar'),
$mainMenuBarAnchor = $('#mainMenuBarAnchor');
// Run this on scroll events.
$window.scroll(function() {
var window_top = $window.scrollTop();
var window_bottom = $window.height() - this.scrollTop() - this.height();
var div_top = $mainMenuBarAnchor.offset().top;
if (window_top > div_top) {
// Make the div sticky.
$mainMenuBar.addClass('stick');
$mainMenuBarAnchor.height($mainMenuBar.height());
}
else if (window_bottom > div_top) {
$mainMenuBar.removeClass('stick');
$mainMenuBarAnchor.height(0);
}
else {
// Unstick the div.
$mainMenuBar.removeClass('stick');
$mainMenuBarAnchor.height(0);
}
});
});
I also found this solution, but can not get it working with jquery 1.7.