获取元素位置的确切方法是什么?

lov*_*ing 5 html javascript

与浏览器窗口的客户区左上角有关。

Ari*_*sky 4

试试这个: http: //www.quirksmode.org/js/findpos.html

  • 的确。jQuery 实现非常复杂:http://code.google.com/p/jqueryjs/source/browse/trunk/jquery/src/offset.js Prototype 的 `Element.viewportOffset()` 也可能值得一看 http ://prototypejs.org/assets/2009/8/31/prototype.js (2认同)