JS代码如下:
/**
* 获取元素在页面的绝对位置
*
* @param
* @arrange (512.笔记) jb51.cc
**/
var getCoords = function (el) {
var Box = el.getBoundingClientRect(), doc = el.ownerDocument, body = doc.body, html = doc.documentElement, clientTop = html.clientTop || body.clientTop || 0, clientLeft = html.clientLeft || body.clientLeft || 0, top = Box.top + (self.pageYOffset || html.scrollTop || body.scrollTop) - clientTop, left = Box.left + (self.pageXOffset || html.scrollLeft || body.scrollLeft) - clientLeft;
return { 'top': top,'left': left };
};
// 来自:编程之家 jb51.cc(jb51.cc)
其中self.pageYOffset为window.self.pageYOffset,是火狐的一个属性,相当于document.body.scrollTop。以下是它的定义: