zoukankan      html  css  js  c++  java
  • Javascript中的文档模式document.compatMode

    今天在看框架的时候无意间看到了document.compatMode,经过一番资料查找,终于搞懂了。
    文档模式在开发中貌似很少用到,最常见的是就是在获取页面宽高的时候,比如文档宽高,可见区域宽高等。
    IE对盒模型的渲染在 Standards Mode和Quirks Mode是有很大差别的,在Standards Mode下对于盒模型的解释和其他的标准浏览器是一样,但在Quirks Mode模式下则有很大差别,而在不声明Doctype的情况下,IE默认又是Quirks Mode。所以为兼容性考虑,我们可能需要获取当前的文档渲染方式。
    document.compatMode正好派上用场,它有两种可能的返回值:BackCompat和CSS1Compat。
    BackCompat:标准兼容模式关闭。浏览器客户区宽度是document.body.clientWidth;CSS1Compat:标准兼容模式开启。 浏览器客户区宽度是document.documentElement.clientWidth。
    那么写了个准确获取网页客户区的宽高、滚动条宽高、滚动条Left和Top的代码:

    if (document.compatMode == "BackCompat") {
        cWidth = document.body.clientWidth;
         cHeight = document.body.clientHeight;
        sWidth = document.body.scrollWidth;
        sHeight = document.body.scrollHeight;
       sLeft = document.body.scrollLeft;
       sTop = document.body.scrollTop;
     }
     else { //document.compatMode == "CSS1Compat"
        cWidth = document.documentElement.clientWidth;
        cHeight = document.documentElement.clientHeight;
       sWidth = document.documentElement.scrollWidth;
       sHeight = document.documentElement.scrollHeight;
        sLeft = document.documentElement.scrollLeft == 0 ? document.body.scrollLeft : document.documentElement.scrollLeft;
       sTop = document.documentElement.scrollTop == 0 ? document.body.scrollTop : document.documentElement.scrollTop;
    }
    
    
  • 相关阅读:
    HBase with MapReduce (MultiTable Read)
    HBase with MapReduce (SummaryToFile)
    HBase with MapReduce (Summary)
    HBase with MapReduce (Read and Write)
    HBase with MapReduce (Only Read)
    Hbase中的BloomFilter(布隆过滤器)
    HBase的快照技术
    How To Use Hbase Bulk Loading
    Cloudera-Manager修改集群的IP
    Java中的HashSet和TreeSet
  • 原文地址:https://www.cnblogs.com/jenry/p/1899354.html
Copyright © 2011-2022 走看看