兼容IE6的fixed定位,解决闪动问题

2014-07-15 22:25

于非IE6可以这样写


[css] view plaincopy


   #top{  

   position:fixed;  

   bottom:0;  

   right:20px;  

   }  



但是IE6是不支持fixed定位的,需要另外重写


[css] view plaincopy


   #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)));  

   }  



使用hack使IE6实现该效果,但是还没有完,这时,这个东东会闪烁,需要以下代码


[css] view plaincopy


   *html{  

   background-image:url(about:blank);  

   background-attachment:fixed;  

   }  



如果使固定在IE6顶部,使用下面代码


[css] view plaincopy


   #top{  

   _position:absolute;  

   _bottom:auto;  

   _top:expression(eval(document.documentElement.scrollTop));  

   }  



固定在底部使用下面代码


[css] view plaincopy


   #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)));  

   }  

^