DOM操作三

1.以一个对象的x和y属性的方式返回滚动条的偏移量

function getScrollOffsets(w){
    //使用指定的窗口,如果不带参数则使用当前窗口
    w= w || window;
    //除了IE 8及更早的版本以外,其他浏览器都能用
    if(w.pageXOffset !=null)
          return {x:w.pageXOffset,y:w.pageYOffset};
    //对标准模式下的IE
    var d=w.document;
    if(document.compatMode=="CSS1Compat"){
          return {x:d.documentElement.scrollLeft,y:d.documentElement.scrollTop};
    }

    //对怪异模式下的浏览器
    return {x:d.body.scrollLeft,y:d.body.scrollTop};

}

2.查询窗口的视口尺寸

function getViewportSize(w){
    //使用指定的窗口,如果不带参数则使用当前窗口
    w= w || window;
    //除了IE 8及更早的版本以外,其他浏览器都能用
    if(w.innerWidth!=null)
          return {w:w.innerWidth,h:w.innerHeight};
    //对标准模式下的IE
    var d=w.document;
    if(document.compatMode=="CSS1Compat"){
          return {w:d.documentElement.clientWidth,h:d.documentElement.clinetHeight};
    }

    //对怪异模式下的浏览器
    return {w:d.body.clientWidth,h:d.body.clientWidth};

}
原文地址:https://www.cnblogs.com/showtime813/p/4481318.html