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

  • 相关阅读:
    5-JVM常用的命令
    4-JVM 参数
    3-JVM垃圾回收算法和垃圾收集器
    2-JVM内存结构
    1-JVM基础
    非常短的git学习笔记
    白话马尔科夫链蒙特卡罗方法(MCMC)
    写了个小游戏,来玩
    胡小兔的 高考2019 游记
    机房志 | 一篇中二的文章
  • 原文地址:https://www.cnblogs.com/nano/p/2302410.html
Copyright © 2020-2023  润新知