ie 6 position fixed

IE6position:fixed问题解决方案 

2013-11-06 18:25:04|  分类: JS/CSS |  标签:ie6  fixed  |举报 |字号订阅

 
 

普通写法

#top{
position:fixed;
bottom:0;
right:20px;
}

IE6中写法

#top{
position:fixed;
_position:absolute;
bottom:0;
right:20px;
_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)));
}

不慌,到这里没完,IE6中position:fixed还有一个拖动滚动条的时候闪动的问题,解决方案如下:

IE6中position:fixed闪动

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

 

 

JS的解决方案

 

JS是我最不愿使用的解决方案,因为这种纯样式的bug用JS来解决有点大材小用,而且JS需要DOM载入后才执行,有可能会出现闪屏的现象.

JS的解决方案很简单,通过设置一个top来实现,top是指分页的上边距离document的上边的长度,可以被分解成下面几项(并不是完整的代码)

top = scrollTop + clientHeight - height(分页的高度)

JS解决IE6下position:fixed元素无效的原理

scrollTop和clientHeight分别用来解决上面两个问题,滚动条的滚动会影响到scrollTop,而窗口的变化会影响到clientHeight,所以当这两个事件被触发时必须重置top,于是就形成类似下面的代码,但这段脚本的刷新率会非常高,估计有性能问题.

window.onresize = window.onscroll = function(){
    //reset top
};
原文地址:https://www.cnblogs.com/czzblog/p/3554352.html