zoukankan      html  css  js  c++  java
  • 关于 document.compatMode

    今天查资料时无意发现一个以前没有注意到过的属性:document.compatMode

    经过一番资料的查询后,了解到以下信息:

    我们都知道IE有两种盒子模型,在不声明 !DOCTYPE 时是混杂模式 (Quirks Mode),在声明了 !DOCTYPE 时与其他标准浏览器一致,是标准模式 (Standards Mode)

    document.compatMode 有两个属性值:

     BackCompat ----- 表示标准规范模式关闭,即当前为混杂模式 (Quirks Mode),此时浏览器客户区宽度为 document.body.clientWidth

    CSS1Compat ---- 表示标准规范模式开启,即当前为标准模式 (Standards Mode),此时浏览器客户区宽度为 document.documentElement.clientWidth

    下面贴一份 准确获取网页客户区的宽高、滚动条宽高、滚动条Left和Top 的代码

     1 if (document.compatMode == "BackCompat") {
     2   cWidth = document.body.clientWidth;
     3   cHeight = document.body.clientHeight;
     4   sWidth = document.body.scrollWidth;
     5   sHeight = document.body.scrollHeight;
     6   sLeft = document.body.scrollLeft;
     7   sTop = document.body.scrollTop;
     8 } else { //document.compatMode == "CSS1Compat"
     9   cWidth = document.documentElement.clientWidth;
    10   cHeight = document.documentElement.clientHeight;
    11   sWidth = document.documentElement.scrollWidth;
    12   sHeight = document.documentElement.scrollHeight;
    13   sLeft = document.documentElement.scrollLeft == 0 ? document.body.scrollLeft : document.documentElement.scrollLeft;
    14   sTop = document.documentElement.scrollTop == 0 ? document.body.scrollTop : document.documentElement.scrollTop;
    15 }

    最后推荐一个网站:

    https://developer.mozilla.org/zh-CN/docs/Web/API/Document/compatMode 

  • 相关阅读:
    Codeforces Round #669 (Div. 2) A、B题题解
    【证明】树上问题-树的直径
    Web前端开发——概述
    Codeforces Round #667 (Div. 3) A
    Codeforces Round #529 (Div. 3) 练习赛
    [Noip2012] 开车旅行 (倍增DP,难)
    国家集训队论文列表(1999-2019)
    博弈论经典模型解析(入门级)
    Problem 1342B
    SCOI2005 互不侵犯 (状态压缩入门题)
  • 原文地址:https://www.cnblogs.com/s-qiu/p/7168894.html
Copyright © 2011-2022 走看看