$(function () { //导航条移动到顶部自动固定 start>>> var ie6 = /msie 6/i.test(navigator.useragent), dv = $('#fixedmenu'), st; dv.attr('otop', dv.offset().top); //存储原来的距离顶部的距离 $(window).scroll(function () { st = math.max(document.body.scrolltop || document.documentelement.scrolltop); if (st >= parseint(dv.attr('otop'))) { if (ie6) {//ie6不支持fixed属性,所以只能靠设置position为absolute和top实现此效果 dv.css({ position: 'absolute', top: st }); }else if (dv.css('position') != 'fixed') dv.css({ 'position': 'fixed', top: 0 }); }else if (dv.css('position') != 'static') dv.css({ 'position': 'static' }); }); //导航条移动到顶部自动固定 <<