本示例使用Javascript实现了滚动页面时,DIV到达顶部时固定在顶部。在IE下效果有点闪,效果网址:http://www.keleyi.com/keleyi/phtml/fixdiv.htm 下面是代码: 复制代码 代码如下: href="http://www.keleyi.com/menu/net/" target="_blank">.NET Javascript jQuery C# 其他 首页 <BR>$(function () { <BR>var ie6 = document.all; <BR>var dv = $('#fixedMenu_keleyi_com'), st; <BR>dv.attr('otop', dv.offset().top); //存储原来的距离顶部的距离 <BR>$(window).scroll(function () { <BR>st = Math.max(document.body.scrollTop || document.documentElement.scrollTop); <BR>if (st > parseInt(dv.attr('otop'))) { <BR>if (ie6) {//IE6不支持fixed属性,所以只能靠设置position为absolute和top实现此效果 <BR>dv.css({ position: 'absolute', top: st }); <BR>} <BR>else if (dv.css('position') != 'fixed') dv.css({ 'position': 'fixed', top: 0 }); <BR>} else if (dv.css('position') != 'static') dv.css({ 'position': 'static' }); <BR>}); <BR>}); <BR>