zoukankan      html  css  js  c++  java
  • expression解决IE6下固定定位的兼容

    本文所使用的技巧是用了一条 Internet Explorer 的 CSS 表达式 (expression) 。你不可以直接使用该表达式,因为它可能会因为缓存而不更新。解决这一点的最简单的方式是使用 eval 包裹你的语句。

    如何解决“振动”的问题?

    显然 IE 有一个多步的渲染进程。当你滚动或调整你的浏览器大小的时候,它将重置所有内容并重新渲染页面,这个时候它就会重新处理 CSS 表达式。这会引起一个丑陋的“振动” bug ,在此处固定位置的元素需要调整以跟上你的(页面的)滚动,于是就会“跳动”。

    解决此问题的技巧就是使用 background-attachment:fixed 为 body 或 html 元素添加一个 background-image:url(about:blank) 。这就会强制页面在重画之前先处理 CSS 。因为是在重画之前处理 CSS ,它也就会同样在重画之前首先处理你的 CSS 表达式。这将让你实现完美的平滑的固定位置元素! CSS代码:

    /*让修复IE6 position:fixed不可用的Bug! */
    
    /* 头部固定 */
    
    .fixed-top{position:fixed;bottom:auto;top:0px;}
    
    /* 底部固定 */
    
    .fixed-bottom{position:fixed;bottom:0px;top:auto;}
    
    /* 左侧固定 */
    
    .fixed-left{position:fixed;right:auto;left:0px;}
    
    /* 右侧固定 */
    
    .fixed-right{position:fixed;right:0px;left:auto;}
    
    /* 上面的是除了IE6的主流浏览器通用的方法 */
    
    /* 修正IE6振动bug */
    
    * html, * html body{background-image:url(about:blank);background-attachment:fixed;}
    
    /* IE6 头部固定定位 */
    
    * html .fixed-top{position:absolute;bottom:auto;
    
    top:expression(eval(document.documentElement.scrollTop));}
    
    /* IE6 右侧固定定位 */
    
    * html .fixed-right{position:absolute;right:auto;
    
    left:expression(eval(document.documentElement.scrollLeft+document.documentElement.clientWidth-this.offsetWidth)-
    (parseInt(this.currentStyle.marginLeft, 10)||0)-(parseInt(this.currentStyle.marginRight, 10)||0))
    ;} /* IE6 底部固定定位 */ * html .fixed-bottom{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)))
    ;} /* IE6 左侧固定定位 */ * html .fixed-left{position:absolute;right:auto; left:expression(eval(document.documentElement.scrollLeft));}

    总结:

    html{
    
    _background:url(about:blank); /* 阻止闪动 in IE6 , 把空文件换成about:blank , 减少请求 */
    
    }
    
    /* 你的图层 */
    
    .positionFixedLayer{
    
    position:fixed;
    
    _position: absolute;
    
    _top:expression(documentElement.scrollTop+documentElement.clientHeight-this.offsetHeight);
    
    _left:expression(documentElement.scrollLeft+documentElement.clientWidth-this.offsetWidth-200);
    
    }

     DEMO:

  • 相关阅读:
    POJ 2240 Arbitrage spfa 判正环
    POJ 3259 Wormholes spfa 判负环
    POJ1680 Currency Exchange SPFA判正环
    HDU5649 DZY Loves Sorting 线段树
    HDU 5648 DZY Loves Math 暴力打表
    HDU5647 DZY Loves Connecting 树形DP
    CDOJ 1071 秋实大哥下棋 线段树
    HDU5046 Airport dancing links 重复覆盖+二分
    HDU 3335 Divisibility dancing links 重复覆盖
    FZU1686 神龙的难题 dancing links 重复覆盖
  • 原文地址:https://www.cnblogs.com/leejersey/p/2797705.html
Copyright © 2011-2022 走看看