67,512
社区成员
发帖
与我相关
我的任务
分享
var ie6 = /msie 6/i.test(navigator.userAgent);
var tableDv = $('.table-css1');
var st;
tableDv.attr('otop', tableDv.offset().top); //存储原来的距离顶部的距离
$(window).scroll(function () {
st = Math.max(document.body.scrollTop || document.documentElement.scrollTop);
if (st>= parseInt(tableDv.attr('otop'))) {
if (ie6) {//IE6不支持fixed属性,所以只能靠设置position为absolute和top实现此效果
tableDv.css({ position: 'absolute', top: st });
}
else if (tableDv.css('position') != 'fixed') tableDv.css({ 'position': 'fixed', top: 0 });
} else if (tableDv.css('position') != 'static') tableDv.css({ 'position': 'static' });
});
哥们 上面的代码 你只需要把固定的id传进去即可 其他不用改