$(window).scroll(function() { var swipeHeight = 200;//完全变色高度 var scrollTop = $(document).scrollTop();//页面滚动高度 var x = scrollTop/swipeHeight; $(".head-bg").css({"opacity":x}); })