免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1578 | 回复: 0
打印 上一主题 下一主题

document.compatMode浅谈动态绑定api [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-11-04 17:48 |只看该作者 |倒序浏览
document.compatMode浅谈动态绑定api




document.compatMode返回的值


•BackCompat-----------------------Quirks Mode
•CSS1Compat----------------------Standards Mode (标准兼容模式)


在不声明Doctype的情况下,IE默认是Quirks Mode




1. 当document.compatMode 为BackCompat时,浏览器视觉区域的宽度document.body.clientWidth
2. 当document.compatMode 为Standards Mode时,浏览器视觉区域的宽度document.documentElement.clientWidth


Js代码
  1. 1./*  
  2. 2.获取页面视觉区域的宽度  
  3. 3.思路需要判断当前的document.compatMode  
  4. 4.*/  
  5. 5.getViewWidth: function(){   
  6. 6.         var doc = document,   
  7. 7.               client = doc.compatMode == 'BackCompat' ? doc.body : doc.documentElement;   
  8. 8.        return client.clientWidth;   
  9. 9.}  
  10. /*
  11. 获取页面视觉区域的宽度
  12. 思路需要判断当前的document.compatMode
  13. */
  14. getViewWidth: function(){
  15.          var doc = document,
  16.                client = doc.compatMode == 'BackCompat' ? doc.body : doc.documentElement;
  17.         return client.clientWidth;
  18. }
复制代码
Js代码
  1. 1./*  
  2. 2.获取页面视觉区域的高度  
  3. 3.思路和上面一致  
  4. 4.*/  
  5. 5.getViewHeight = function(){   
  6. 6.     var doc = document,   
  7. 7.           client = doc.compatMode == 'BackCompat' ? doc.body : doc.documentElement;   
  8. 8.     return client.clientHeight;   
  9. 9.}  
  10. /*
  11. 获取页面视觉区域的高度
  12. 思路和上面一致
  13. */
  14. getViewHeight = function(){
  15.      var doc = document,
  16.            client = doc.compatMode == 'BackCompat' ? doc.body : doc.documentElement;
  17.      return client.clientHeight;
  18. }
复制代码
Js代码
  1. 1./*  
  2. 2.仿照使用$.each----动态绑定 节约复用  
  3. 3.*/  
  4. 4.$.each(['Width','Height'],function(i,v){   
  5. 5.      jQuery.fn['getView'+v] = function(){   
  6. 6.                  var doc = document,   
  7. 7.                        client = doc.compatMode == 'BackCompat' ? doc.body :                               doc.documentElement;   
  8. 8.                  var type = 'client'+v;   
  9. 9.                  return client[type];   
  10. 10.      }   
  11. 11.});  
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP