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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值