0
在我的頁面中,當我滾動菜單被更改。但是,當我在聯繫部分並刷新頁面時,它會選擇主頁,但會保留在聯繫人部分。如何選擇刷新菜單?
var lastId,
topMenu = $(".menu"),
topMenuHeight = topMenu.outerHeight()+15,
menuItems = topMenu.find("a"),
scrollItems = menuItems.map(function(){
var item = $($(this).attr("href"));
if (item.length) { return item; }
});
$(window).scroll(function(){
var fromTop = $(this).scrollTop()+topMenuHeight;
var cur = scrollItems.map(function(){
if ($(this).offset().top < fromTop)
return this;
});
cur = cur[cur.length-1];
var id = cur && cur.length ? cur[0].id : "";
if (lastId !== id) {
lastId = id;
menuItems
.parent().removeClass("active")
.end().filter("[href=#"+id+"]").parent().addClass("active");
}
});
你希望你的菜單中還同步對嗎? – dreamweiver
請你詳細說明一下。 –
當我在聯繫部分並刷新頁面時,我會在聯繫人部分中說,但不是菜單,它會激活「主頁」菜單項。但我需要激活「聯繫人」項目菜單。 – user3214264