浮动导航
//初始化全局变量GLOBAL.onscrollY.thisy【滚动的高度】 GLOBAL.namespace('onscrollY'); GLOBAL.onscrollY.thisy=0; $(window).resize(function(){ GLOBAL.onscrollY.thisy = (document.body.scrollTop||document.documentElement.scrollTop); }); $(window).scroll(function(){ GLOBAL.onscrollY.thisy = (document.body.scrollTop||document.documentElement.scrollTop); }); //【floatMenu】超过【Gover】时增加类【onFloat】——可用于浮动导航 //实例调用 onFixed('.floatMenu','#Gover','onFloat'); function onFixed(floatMenu,Gover,onClass){ this.floatMenu=$(floatMenu); this.Gover=$(Gover); this.onClass=onClass; $(window).scroll(function(){ if( GLOBAL.onscrollY.thisy >this.Gover.offset().top ){ this.floatMenu.addClass(this.onClass); }else{ this.floatMenu.removeClass(this.onClass); } }); }