weird ... apparently my code VS offset does not change in FireFox while in
IE I obtain different behaviours.
offset seems to be in any case the answer, but in IE I have a couple of
pixels that are not aligned.
<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;width:200px;background-color:#EEE;">
Hello relatively absolute position
</div>
</div>
<div id="out"
style="position:absolute;height:100px;width:200px;background-color:#DDD;"></div>
<script src="jquery-1.2.6.min.js"></script>
<script>
onload = function(){
var p = $("#nested").offset();
$("#out").css({
top:p.top,
left:p.left
});
}
</script>
Any guess?
On Thu, Jan 22, 2009 at 12:12 PM, Andrea Giammarchi <
[email protected]> wrote:
> Uhm ... I tried offsetParent and I was stuck with {0,0} but maybe you are
> right and I am going to try :D
>
> Cheers
>
>
> On Thu, Jan 22, 2009 at 11:43 AM, Jörn Zaefferer <
> [email protected]> wrote:
>
>>
>> Isn't that what offset() does? "Get the current offset of the first
>> matched element relative to the document."
>>
>> Jörn
>>
>> On Thu, Jan 22, 2009 at 12:32 PM, Andrea Giammarchi
>> <[email protected]> wrote:
>> > 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
-~----------~----~----~----~------~----~------~--~---