Something like this, for example ( at least this is how I have solved right
now )
$.fn.position = function(position){
return function(absolute){
if(absolute === true){
var p, e = this[0];
if(e){
p = position.call(this);
while(e = e.offsetParent)try{
with(position.call($(e))){
p.left += left;
p.top += top;
}
}catch(e){}
}
}
else
var p = position.apply(this, arguments);
if(p){// just for me ...
p.x = p.left;
p.y = p.top;
};
return p
}
}($.fn.position);
Regards
On Thu, Jan 22, 2009 at 11:08 AM, Andrea Giammarchi <
[email protected]> wrote:
> You know that when an element has position absolute, it does not necessary
> mean that its position is from top and left of the page.
>
> For example, if I have a situation like this one:
> <div style="position:relative;top:100px;left:100px;">
> This text is not visible
> <div id="nested"
> style="position:absolute;top:0px;left:0px;height:100px;background-color:#FFF;">
> Hello relatively absolute position
> </div>
> </div>
> The nested div with absolute position will be positioned at the top left
> corner of its parent with relative position.
>
> As summary, this is my question:
> is it an expected behavior that $("#nested").position() is {top:0, left:0}
> ?
> Is there any chance jQuery will introduce a boolean argument to calculate
> the real position of an element with or without "position:static" convention
> ?
>
> In my case it would be useful for drawing functionality with spread
> elements inside floating containers ...
>
> Regards
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---