最完美修正IE6position:fixed的BUG

IE6是不支持position:fixed的,可以使用CSS表达式expression来解决!

先粘贴代码

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>fixed</title>
<style type="text/css">
*{ margin:0px; padding:0px;}
html{ _background-attachment:fixed; _background-image:url(about:blank);}//完美解决IE6跳动
a#box{ right:0px;bottom:0px; font-size:12px; color:#FFF; text-align:center; line-height:15px; text-decoration:none; display:block; width:30px; padding:10px; height:30px; background-color:#666; position:fixed;_position:absolute; _top:expression(parseInt(document.documentElement.scrollTop)+parseInt(document.documentElement.clientHeight)-50);}
a#box:hover{ background-color:#000;}
</style>
</head>
<body>
<div style="height:3000px;"></div>
<a href="#" id="box">
返回顶部
</a>
</body>
</html
IE有一个多步的渲染进程。当你滚动或调整你的浏览器大小的时候,它将重置所有内容并重画页面,这个时候它就会重新处理css表达式。这会引起一个丑陋的“振动”bug,在此处固定位置的元素需要调整以跟上你的(页面的)滚动,于是就会“跳动”。
解决此问题的技巧就是使用background-attachment:fixed为body或html元素添加一个background-image。这就会强制页面在重画之前先处理CSS。因为是在重画之前处理CSS,它也就会同样在重画之前首先处理你的CSS表达式。这将让你实现完美的平滑的固定位置元素!
background-image无需一张真实的图片,可以设置成about:blank。
如 html{ _background-attachment:fixed; _background-image:url(about:blank);}
这样IE6就完美解决了
posted @ 2012-07-19 14:32  justlancer  阅读(184)  评论(0编辑  收藏  举报