superdezign wrote:
The function returns an object with the x and y position, but you can simplify it to just return an integer of the y position.
So i can get the y value with GetPosition('div2')['y'] ??
superdezign wrote:
It depends on the browser. Some browsers do it for each pixel (I think IE does), and others only do it after the resize is complete (i.e. Mozilla).
IE does, i just figured out.
superdezign wrote:
obj.nodeName is there to ensure that you are providing an HTML element to the function... Are you sure you are getting null? Did you try to place an alert in the 'return null' branch to be sure?
Yes, i changed the return null with alert('nothing') and it alerted

If i take out obj.nodeName from the function, it doesn't even work anymore and gives another Object Required error...
Code: Select all
function GetPosition(obj)
{
if(!obj.nodeName)
{
alert('nothing')
}
var y, tmp;
for(y = 0, tmp = obj; tmp; tmp = tmp.offsetParent)
{
y += tmp.offsetTop;
document.getElementById('body2').innerHTML = y
}
return {'y' : y};
}
Oh and doing this:
Code: Select all
function GetPosition(obj)
{
obj.nodeName
var y, z, tmp;
for(y = 0, z = 0, tmp = obj; tmp; tmp = tmp.offsetParent)
{
y += tmp.offsetTop;
z = z + 1;
document.getElementById('body2').innerHTML = z
}
return {'y' : y};
}
... z in body2 was always 1 (meaning that the for() is executed only once? ... it should be run 2-3 times (not sure which) becouse the div's parent is not body but another div
Looking forward for your answer (honestly... i wanna get over this, becouse it actually looks like i'm doing nothing becouse it's quite pathetically simple at first looks

)