Coordinates when there is an offset in the page


How to get an object real coordinates when there is a zoom or an scroll bar on the page ?

var scrOfX = 0, scrOfY = 0;
if (typeof(window.pageYOffset) == 'number' ) {
//Netscape compliant
scrOfY = window.pageYOffset;
scrOfX = window.pageXOffset;
} else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
//DOM compliant
scrOfY = document.body.scrollTop;
scrOfX = document.body.scrollLeft;
} else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
//IE6 standards compliant mode
scrOfY = document.documentElement.scrollTop;
scrOfX = document.documentElement.scrollLeft;
}

myObject.Coord.x += scrOfX;
myObject.Coord.y += scrOfY;

via infos-du-net board

Fab

Engineer - Web Juggler - Confit de canard
Fab

Latest posts by Fab (see all)

Leave a comment

Your email address will not be published. Required fields are marked *