$(document).scroll(function(){ // 页面往下滚动后添加的类名 if(window.scrollY >= 50){ $('body > .main > div:nth-child(1)').addClass('downClass'); }else{ $('body > .main > div:nth-child(1)').removeClass('downClass'); } // 【使用方法】 // 1、使用时可自由设置距离顶部的高度 // 2、downClass类名如不满足可自由编辑为其他类名 // 3、具体实现的样式需要自行到样式文件里定义downClass或者已修改为其他的类名样式 });