On Tue, 3 Oct 2006, Brandon Aaron wrote:

> On 10/3/06, Dave Benjamin <[EMAIL PROTECTED]> wrote:
>> I'm not too crazy about .top() and .left() because of the need to
>> concatenate and un-concatenate 'px' everywhere.
>
> I can understand this and it is something I'm trying to decide how I
> want to handle. The offset plugin I wrote returns a unit-less number
> and it should be that way but I was thinking about including a
> property: toppx and leftpx that would include + 'px'. Not sure how
> useful that really is though ... and while I talking about this plugin
> ...

Well, it's not much of a savings... o.toppx vs o.top+'px' is about the 
same to me.

> I was thinking about allowing it to take another element or expression
> as a parm and get the relative offset instead of going all the way to
> the body. Does anyone think this would be useful? It shouldn't add
> much overhead to the method for those that don't need it.

Yeah, this is one thing that troubles me about my .x() and .y() methods - 
they are asymmetrical with respect to reads and writes, since writes 
modify the CSS attribute directly, but reads take nesting into account. 
Being able to choose between local and global coordinates seems helpful.

> I was also thinking about taking a hash of top and left as a param.
> The top and left would be numbers to relatively offset the element by.
> This sounds like what you are talking about and would remove the
> annoyance of the + 'px' all over the place. However, the call would
> look like this: $().offset({ top: 10, left: 10 }); I guess that is
> less typing than: $().top(10+'px').left(10+'px');

I much prefer $().offset({ top: 10, left: 10 }) to the chaining of .top() 
and .left(). It's more readable, and easier to modify. (IMHO)

> One issue I have with this is what should it actually return? I don't
> think it is a good idea to change return types but it would make most
> sense in this situation to return the jQuery object. The other issue
> is that calling offset like this would suggest that it acts on all the
> elements in the jQuery object whereas just $().offset() acts only on
> the first. So .... yeah I've thinking hard about it and could use some
> opinions.

Well, I'm personally not a big fan of method chaining, period. ;) However, 
I would normally ignore the result of .offset( {...} ), so I don't really 
care. Might as well be the jQuery object.

Regarding multiple matched elements, I think it makes the most sense to 
take the minimum of "left" and "top"... and if there is also "right" and 
"bottom", take the maximum of those. That way it gives you a bounding box 
for all matched elements.

For setting... that's trickier. The simplest thing would be to set all 
elements to be the same. But that's inconsistent with the bounding box 
metaphor, which would suggest only setting the outermost matched element, 
or otherwise maintaining that the relative position of the elements to 
each other remains stable.

Dave

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to