1
好吧...我有一個導航菜單,當您向下滾動時,它會變爲固定菜單頁面附帶的頂部。具有絕對位置和較低Z指數的Div顯示在較高Z指數(固定位置)頂部
但由於某些原因,我有了一個絕對位置和下方的z-index比菜單,但它仍然顯示在菜單頂部的網頁div ...
這裏的功能它將菜單設置爲固定過去某個點。
$(function(){
var pos = $('#nav').offset().top;
$(window).scroll(function(){
if($(window).scrollTop() > pos) {
$('#nav').parent().parent().css({position: 'fixed', top: '0px', background: '#fff', width: '100%', 'z-index': 9002, left:0});
} else {
$('#nav').parent().parent().css({position: 'static', top: '0px', background: 'none', width: '100%', 'z-index': 1});
}
});
});
這是顯示在頂部時,它不應該...
.header {
position: relative;
z-index: 1;
margin: 0;
padding: 0; }
此外,here你可以看到它發生的例子,你向下滾動頁面的DIV。
你確定了'你張貼.header' CSS是正確?根據我在firefox中的調試,我注意到'.header'類實際上有一個9001的z-index。查看你的文件的原始html txt,我發現你的'.header'的CSS應用了z-index 。這是我的瀏覽器中的錯誤嗎?如果不是,那將是什麼導致你的問題。 –
對不起,我只在本地編輯。反正它不會有什麼不同,因爲菜單有9002 z-index!但我修正了它,現在只有1個,正如我在主文章中所說的那樣。 –