您的位置:首页 > 其它

position:fixed;在IE6中的完美实现

2010-09-14 11:24 387 查看
要点:要用html5

[html]
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title></title>
<style>
body{
_background: url(about:blank) fixed;
}
.he1200{
height:1200px;
}
#fixable{
position:fixed;
width:200px;
height:30px;
border:1px solid red;
}
</style>
</head>
<body>
<div class="he1200"></div>
<div id="fixable">fixablei in ie6</div>

<script>
function fixable(d,c) {
d.style.left = c.left;
if (/msie (\d+\.\d)/i.test(navigator.userAgent) && parseFloat(RegExp["\x241"]) && parseFloat(RegExp["\x241"])<7) {
d.style.position='absolute';
d.style.setExpression("top", "eval((document.documentElement||document.body).scrollTop+" + c.top + ") + 'px'");
}else{
d.style.top = c.top+'px';
}
}

var doc = document.compatMode == "BackCompat" ? document.body : document.documentElement;
fixable(document.getElementById('fixable'),{top:doc.clientHeight-300,left:"600px"});
</script>
</body>
</html>
[/html]

另外有哥们儿修改一下,和doctype没关系了,和html5也没关系了,但一定要加上doctype
[html]</pre>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>
<head>
<title></title>
<style>
body {
_background: url(about:blank) fixed;
}
.he1200 {
height:1200px;
}
#fixable {
position:fixed;
left:100px;
top:300px;
_position:absolute;
_top:expression((document).documentElement.scrollTop+300);
}
</style>
</head>
<body>
<div></div>
<div id="fixable">fixablei in ie6</div>
</body>
</html>
<pre>[/html]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: