求几行代码-导航栏固定

浏览:1147 发布日期:2013/10/10 分类:求助交流
如图这种,页面下滑时,导航栏固定,求代码,js刚学,搞不定

刚改了一段代码<script type="text/javascript">
$(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');
}
})
});
</script>

这样可否?
最佳答案
评论( 相关
后面还有条评论,点击查看>>