zoukankan      html  css  js  c++  java
  • ie6 fixed 很纠结~这个js就解决了

    ie6真是个老大难的问题啊 前端人员心中永远的通

    为了他一个浏览器 付出了我们多少代码啊~55

    <script type="text/javascript">
          var position = function(){
              var isIE6 = !-[1,] && !window.XMLHttpRequest,
                  html = document.getElementsByTagName('html')[0],
                  dd = document.documentElement,
                  db = document.body,
                  dom = dd || db,
                  // 获取滚动条位置
                  getScroll = function(win){
                      return {
                          left: Math.max(dd.scrollLeft, db.scrollLeft),
                          top: Math.max(dd.scrollTop, db.scrollTop)
                          };
                  };
        
              // 给IE6 fixed 提供一个"不抖动的环境"
              // 只需要 html 与 body 标签其一使用背景静止定位即可让IE6下滚动条拖动元素也不会抖动
              // 注意:IE6如果 body 已经设置了背景图像静止定位后还给 html 标签设置会让 body 设置的背景静止(fixed)失效
              if (isIE6 && document.body.currentStyle.backgroundAttachment !== 'fixed') {
                  html.style.backgroundImage = 'url(about:blank)';
                  html.style.backgroundAttachment = 'fixed';
              };
        
              return {
                  fixed: isIE6 ? function(elem){
                      var style = elem.style,
                          doc = getScroll(),
                          dom = '(document.documentElement || document.body)',
                          left = parseInt(style.left) - doc.left,
                          top = parseInt(style.top) - doc.top;
                      this.absolute(elem);
                      style.setExpression('left', 'eval(' + dom + '.scrollLeft + ' + left + ') + "px"');
                      style.setExpression('top', 'eval(' + dom + '.scrollTop + ' + top + ') + "px"');
                  } : function(elem){
                      elem.style.position = 'fixed';
                  },
        
                  absolute: isIE6 ? function(elem){
                      var style = elem.style;
                      style.position = 'absolute';
                      style.removeExpression('left');
                      style.removeExpression('top');
                  } : function(elem){
                    elem.style.position = 'absolute';
                  }
              };
          }();
          </script>

    //使用方法

    var id = document.getElementById('id');

    position.fixed(id);

    position.absolute(id);

  • 相关阅读:
    HDU3718 Similarity 最大权值匹配
    HDU2853 Assignment 最大权值匹配+简直是太神了
    HDU3488 Tour 再次感受到KM的强大
    ZOJ2575 Full of Painting 动态规划
    ZOJ2571 Big String Outspread 模拟
    POJ3565 Ants 空间点对不相交匹配最小权值匹配
    Fleury(弗罗莱)算法求欧拉路径
    HDU2426 Interesting Housing Problem 最大权值匹配不能完成匹配的处理
    POJ1392 Ouroboros Snake 欧拉回路
    HDU2255 奔小康赚大钱 最大权值匹配
  • 原文地址:https://www.cnblogs.com/nano/p/2302410.html
Copyright © 2011-2022 走看看