How can I have a sliding menu div that doesn't move unless the page is scrolled down past a certain point如何在頁腳
我使用的代碼從這個鏈接,一個浮動菜單停止浮動(滑動)股利。它有如何停止標題停止浮動,但不是在頁腳。我如何修改此代碼以停止在頁腳?
//// 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});
});
我是應該停止在頁腳另一個類似的代碼,但它不工作:
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});
}
);
}
);
不是真的,吉姆,但感謝您的及時回覆。我有一個有目的的浮動導航菜單,以便用戶不必滾動回到頂部,但它在底部時重疊頁腳。最簡單的解決方案是使頁腳更小(從300px到推薦的241px),但我只是想固執地嘗試使用代碼。 – Matt 2009-11-14 01:12:19