建议:尽可能的手写代码,可以有效的提高学习效率和深度。
由于IE6并不支持position:fixed,所以导致很多好的效果都无法实现,但是在IE6下并不是不能够实现,下面就通过一段实例介绍一下如何实现此种效果。代码实例如下:

复制代码代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="http://imgbuyun.weixiu-service.com/up79/202309/t04zxy3txyj" />
<title>蚂蚁部落</title>
<style type="text/css">
body
{
margin:40px;
padding:0px;
border:1px solid blue;
}
.first
{
width:300px;
height:600px;
border:1px solid red;
margin:20px;
}
.first .fixed
{
width:100px;
height:100px;
background-color:black;
position:fixed;
_margin-top:20px;
_position:absolute;
_top:expression(eval(document.documentElement.scrollTop));
left:20px;
top:20px;
}
</style>
</head>
<body>
<div class="first">
<div class="fixed"></div>
</div>
</body>
</html>

以上代码可以兼容IE6和其他主流浏览器,实现此效果的核心代码是:

复制代码代码如下:
_top:expression(eval(document.documentElement.scrollTop));

注意:加上了上面这一行代码之后,IE6下top功能失效了,所以要加一个_margin-top。
虽然上面的代码实现了想要的功能,但是还是有点问题,那就是当拖动滚动条的时候会出现颤抖现象。代码修改如下:

复制代码代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="http://imgbuyun.weixiu-service.com/up79/202309/t04zxy3txyj" />
<title>蚂蚁部落</title>
<style type="text/css">
*html
{
background-image:url(about:blank);
background-attachment:fixed;
}
body
{
margin:40px;
padding:0px;
border:1px solid blue;
}
.first
{
width:300px;
height:600px;
border:1px solid red;
margin:20px;
}
.first .fixed
{
width:100px;
height:100px;
background-color:black;
position:fixed;
_margin-top:20px;
_position:absolute;
_top:expression(eval(document.documentElement.scrollTop));
left:20px;
top:20px;
}
</style>
</head>
<body>
<div class="first">
<div class="fixed"></div>
</div>
</body>
</html>

以上代码完美实现了我们想要的功能,在第一段实例基础上添加如下代码:

复制代码代码如下:
*html
{
background-image:url(about:blank);
background-attachment:fixed;
}

ie6下实现position:fixed效果实例介绍