offsetleft兼容性简单介绍
分类:实例代码
关于此属性的基本用法可以参阅offsetleft属性用法详解一章节。
此属性具有一定的兼容性问题,那就是在IE7浏览器中,它的返回值是想对于最近的父辈元素的左侧的距离。
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.pipipi.net/" /> <title>前端教程网</title> <style type="text/css"> * { margin: 0px; padding: 0px; } #main { width: 300px; height: 300px; background: red; position: absolute; left: 100px; top: 100px; } #box { width: 200px; height: 200px; background: blue; margin:50px; overflow:hidden; } #inner { width: 50px; height: 50px; background: green; text-align: center; line-height: 50px; margin: 50px; } </style> <script type="text/javascript"> window.onload=function(){ var inner=document.getElementById("inner"); inner.innerHTML=inner.offsetLeft; } </script> </head> <body> <div id="main"> <div id="box"> <div id="inner"></div> </div> </div> </body> </html>
上面的代码在其他浏览器中返回值是100,但是在IE7浏览器中返回值是50。
至于IE6没有测试,感兴趣的大家可以做一下测试。