原生
1.function getScrollTop() {
var scrollTop = 0;
if (document.documentElement && document.documentElement.scrollTop) {
scrollTop = document.documentElement.scrollTop;
} else if (document.body) {
scrollTop = document.body.scrollTop;
}
return scrollTop;
}
jQuery
2.$(window).scroll(function(){
var $scroll_height = $(document).scrollTop();
if($scroll_height > 10){
$("#header").css("background","rgba(0,0,0,.95)")
} else {
$("#header").css("background","")
}
})