2016-07-01 33 views

回答

0

你可以做這樣的事情......

var thisScroll = 0, lastScroll = 0; 
var cutoff = 145 (whatever the threshold for the switch should be) 
$(window).scroll(function(){ 
if(thisScroll > lastScroll && thisScroll > cutoff { 
    $(navbar).addClass('fixed'); 
} 
else if (lastScroll > thisScroll && lastScroll < cutoff{ 
    $(navbar).removeClass('fixed'); 
} 
}); 

然後,你可以使用CSS做粘邊-nav(只需添加位置:固定和其他任何你想轉換的東西轉換)

+0

我想使自定義phtml模板代碼做同樣的事情。 –

+0

如果您不介意側欄始終處於固定狀態,而不是像導航欄一樣向下滾動,則可以使用CSS而不使用JavaScript。如果你需要保留在一個phtml模板中,你可以添加一個內聯樣式塊到你的側邊欄,位置:固定,並可能從頂部距離一段距離,以補償它被鎖定。 – will

+0

通過做位置固定它是重疊頁腳。 –

相關問題