您的位置:首页 > 其它

IE6不支持fixed

2016-05-27 16:15 204 查看
#goto-top {
display:none;
position:fixed;
width:38px;
height:36px;
background:url(../images/goto-top.png) no-repeat 0 0;
bottom:40px;
right:40px;
-webkit-transition:all 0.2s;
-moz-transition:all 0.2s;
-o-transition:all 0.2s;
transition:all 0.2s;
z-index:9999;
}
/*ie6*/
* html body {background-image:url(about:blank);background-attachment:fixed}    /*解决IE6闪动*/
* html #goto-top{
_position:absolute; _bottom:auto; _top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-(parseInt(this.currentStyle.marginTop,10)||0)-(parseInt(this.currentStyle.marginBottom,10)||0)));
_margin-bottom: 40px;    /*定位底部*/
}


注释:right 跟 left 属性可以用绝对定位的办法解决,而 top 跟 bottom 就需要用上面的表达式来实现。其中在
_position:absolute;
中的
_
符号只有 IE6 才能识别,目的是为了区分其他浏览器。 

使元素固定在浏览器的顶部
#top{
_position:absolute;
_bottom:auto;
_top:expression(eval(document.documentElement.scrollTop));}

使元素固定在浏览器的底部
#top{
_position:absolute;
_bottom:auto;
_top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-(parseInt(this.currentStyle.marginTop,10)||0)-(parseInt(this.currentStyle.marginBottom,10)||0)));}

这两段代码只能实现在最底部跟最顶部,你可以使用
_margin-top:10px;
或者
_margin-bottom:10px;
修改其中的数值控制元素的位置。

position:fixed; 闪动问题

现在,问题还没有完全解决。在用了上面的办法后,你会发现:被固定定位的元素在滚动滚动条的时候会闪动。解决闪动问题的办法是在 CSS 文件中加入:

*html{
background-image:url(about:blank);
background-attachment:fixed;}

其中
*
是给 IE6 识别的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: