如图这种,页面下滑时,导航栏固定,求代码,js刚学,搞不定刚改了一段代码<sc
$(document).ready(function(e) {
t = $('#header').offset().top;
h =$('#header').height();
$(window).scroll(function(e){
s = $(document).scrollTop();
if(s > t){
$('#header').css('position','fixed');
$('#header').css('top',0+'px');
$('#container').css('margin-top',h+'px');
}else{
$('#header').css('position','');
$('#container').css('margin-top','0px');
}
})
});
</sc
这样可否?
最佳答案