zoukankan      html  css  js  c++  java
  • 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};
    
    }
  • 相关阅读:
    169. Majority Element
    283. Move Zeroes
    1331. Rank Transform of an Array
    566. Reshape the Matrix
    985. Sum of Even Numbers After Queries
    1185. Day of the Week
    867. Transpose Matrix
    1217. Play with Chips
    766. Toeplitz Matrix
    1413. Minimum Value to Get Positive Step by Step Sum
  • 原文地址:https://www.cnblogs.com/showtime813/p/4481318.html
Copyright © 2011-2022 走看看