HTML代碼就不展示了,重點展示一下實現導航欄固定的jQuery核心代碼。
$(window).scroll(function(){
if($(window).scrollTop()>100){
$(".nav").addClass("fixed");
}else{
$(".nav").removeClass("fixed");
}
});