让IE6 支持fixed

fixed 很酷,可是IE6不支持,在IE6还是主流浏览器的年代,不得不考虑对它的兼容性。
万恶的IE6!

解决这一IE6 bug有几种方法:
1.CSS模拟

body{height:100%;overflow:hidden;position:relative}
.fixed{position:absolute;top:10px;left:10px}
.container{height:100%;overflow:auto}

2.JS实现

<script language="javascript" type="text/javascript">
window.onload=function(){
if(!window.XMLHttpRequest){//ie6
var n=0;  //top值
var obj=document.getElementById("topbox"); //position:fixed对象
window.onscroll=function(){obj.style.top=(document.body.scrollTop||document.documentElement.scrollTop)+n+'px';}
window.onresize=function(){obj.style.top=(document.body.scrollTop||document.documentElement.scrollTop)+n+'px';}
}
}
</script>


两种方法各有优劣
也许还有第三种

文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: fixed IE6
相关日志:
评论: 0 | 引用: 0 | 查看次数: 612
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1000 字 | UBB代码 开启 | [img]标签 关闭