当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 各种常用浏览器getBoundingClientRect的解析

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 各种常用浏览器getBoundingClientRect的解析


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 353 ::
收藏到网摘: n/a

getBoundingClientRect 先上测试代码
复制代码 代码如下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>管理系统</title>
</head>
<body style="" onselectstart="return false;" ><!--7699c7-->
<div id="w3124" style="border:1px solid #ff0000;position:relative;top:200px;left:400px;width:400px;">
</div>
<SCRIPT>
alert(document.getElementById("w3124").getBoundingClientRect().top);
</SCRIPT>
</body>
</html>

下面是alert结果
IE、FF、Chrome:208
IE内核的Maxthon:215
IE内核的TheWorld:217
当body加上margin:0;padding:0 的时候IE、FF、Chrome、Maxthon下均为200,而只有TheWorld为202
然后把HTML代码头部的DOCTYPE声明去掉的时候FF、Chrome、Maxthon值均为200,而IE由于进入Quirks模式,此时的值为202,而TheWorld仍为为202
结论
FF、Chrome、Maxthon为始终坚持标准模式(Standards Mode),IE在加了声明后也进入标准模式(Standards Mode),只有TheWorld始终坚持Quirks模式,万恶!
建议
为了兼容把body加上margin:0;padding:0,注意加DOCTYPE声明(有了它IE还是挺听话的)
另:
1.通篇用绿色希望大家眼睛能放松些。
2.小弟第一次发博客,心灵脆弱,无法承受各种打击,如果有啥不对的,请指正,我一定虚心改正,拍砖请轻一点,谢谢啦
3.参考文献