Сообщение от devote
|
var box = elem.getBoundingClientRect();
|
полный вариант
var Obj = {
positX : function (elem){
var body, html, scrollX, scrollY, box, x = 0, y = 0;
box = elem.getBoundingClientRect();
body = document.body;
html = document.documentElement;
scrollX = window.pageXOffset || html.scrollLeft || body && body.scrollLeft || 0;
scrollX = html.scrollLeft || body && body.scrollLeft || 0;
x = box.left + scrollX - (html.clientLeft || body.sclientLeft || 0);
return Math.round(x);
},
positY : function (elem){
var body, html, scrollX, scrollY, box, x = 0, y = 0;
box = elem.getBoundingClientRect();
body = document.body;
html = document.documentElement;
scrollY = window.pageYOffset || html.scrollTop || body && body.scrollTop || 0;
scrollY = html.scrollTop || body && body.scrollTop || 0;
y = box.top + scrollY - (html.clientTop || body.sclientTop || 0);
return Math.round(y);
}
};