直接上代码:
$(window).scroll(function(){ //开始监听滚动条
var top = $(document).scrollTop(); //滚动条距离顶部的高度
if(top > 120 ) {
$(".header-nav").css({
'position': 'fixed',
'top': '-120px',
'z-index': 99
})
} else{
$(".header-nav").css({
'position': 'absolute',
'top': 0,
'z-index': 99
})
}
})