I used the code from this link for a floating menu. it has how to stop the stop float at the header, but not at the footer. How can I modify this code to stop at the footer?
//// CONFIGURATION VARIABLES:
var name = "#sidebar";
var menu_top_limit = 0;
var menu_top_margin = 0;
var menu_shift_duration = 500;
var menuYloc = null;
///////////////////////////////////
$(window).scroll(function()
{
// Calculate the top offset, adding a limit
offset = menuYloc + $(document).scrollTop() + menu_top_margin;
// Limit the offset to 241 pixels...
// This keeps the menu out of our header area:
if(offset < menu_top_limit)
offset = menu_top_limit;
// Give it the PX for pixels:
offset += "px";
// Animate:
$(name).animate({top:offset},{duration:menu_shift_duration,queue:false});
});
I have another similar code that is supposed to stop at the footer, but it is not working:
var name = "#sidebar";
var menuYloc = null;
var footer = #footer ; //Specify the ID for your footer.
$(document).ready(
function()
{
menuYloc = parseInt($(name).css("top").substring(0,$(name).css("top").indexOf("px")))
$(window).scroll(
function()
{
var offset = menuYloc + $(document).scrollTop();
var anotherOffset = offset;
var docTop = $(window).scrollTop();
var footerTop = $(footer).offset().top;
var maxOffset = footerTop - $(name).height() - 20;
var minOffset = docTop;
offset = offset > maxOffset ? maxOffset : offset;
offset = offset < minOffset ? minOffset : offset;
$(name).animate({top:offset + px },{duration:500,queue:false});
}
);
}
);