ie6下的fixed

来源:互联网 发布:山西大学教务网络 编辑:程序博客网 时间:2024/04/30 15:34

    在其它浏览器中,css属性设置成fixed都是有效果的,但是在ie6中,却存在兼容性的问题,不支持这个属性。

    解决方法:设置hack

.style{

width:360px;

height:230px;

position: fixed;

left: 50%;

top:50%;

margin-top:-115px;

margin-left:-230px;

_position:absolute;

_top:expression(460+documentElement.scrollTop +"px"); //documentElement.scrollTop获取到滚动条离顶端的位置

}

这样设置过后就会有fixed的效果了。

但是,如果在页面上有两个元素都要设置成这种,第二个这样设置的就不会有效果了。又怎么解决了,只有用js设置了:

if($.browser.msie && $.browser.version ==6){
window.attachEvent('onscroll',function(){
var _top = document.documentElement.scrollTop,
$obj = $('
.style');

$obj.css('top',
460+_top)
});
};
   

原创粉丝点击