[jQuery] Re: Why isn't there top() and left() methods in the dimension plugin ?
You can very easily add these helper methods to your own app like this: jQuery.fn.left = function() { return this.offset({scroll:false}).left; }; jQuery.fn.top = function() { return this.offset({scroll:false}).top; }; -- Brandon Aaron On 8/28/07, Olivier Percebois-Garve [EMAIL PROTECTED] wrote: Okay, I'm doing a lot of jQuery today so please pardon me if I'm sending too much emails here. I'm annoyed with the (otherwise great) dimension plugin because there is no direct way to get the top and left position of an element. So all over my code I have things such as : $errorBoxOffset = {}; element.offset({scroll: false}, $errorBoxOffset); $left = $errorBoxOffset.left; $top = $errorBoxOffset.top; Have I missed something in the dimension doc ? Do you think it would make sense to add such functions to the dimensions plugin ? -Olivier
[jQuery] Re: Why isn't there top() and left() methods in the dimension plugin ?
Hi Olivier, The Dimensions plugin has a very powerful .offset() method. Perhaps that is what you're looking for? For a demo of Dimemsions methods, check out this companion page to the Dimensions chapter in jQuery Reference Guide: http://book.learningjquery.com/3810_10_code/dimplugin.html --Karl _ Karl Swedberg www.englishrules.com www.learningjquery.com On Aug 28, 2007, at 8:39 AM, Olivier Percebois-Garve wrote: Okay, I'm doing a lot of jQuery today so please pardon me if I'm sending too much emails here. I'm annoyed with the (otherwise great) dimension plugin because there is no direct way to get the top and left position of an element. So all over my code I have things such as : $errorBoxOffset = {}; element.offset({scroll: false}, $errorBoxOffset); $left = $errorBoxOffset.left; $top = $errorBoxOffset.top; Have I missed something in the dimension doc ? Do you think it would make sense to add such functions to the dimensions plugin ? -Olivier
[jQuery] Re: Why isn't there top() and left() methods in the dimension plugin ?
Wow your too fast guys. It seems that I was using offset() the wrong way. $left = element.offset().left; $top = element.offset().top; is fine for me in replacement of : $errorBoxOffset = {}; element.offset({scroll: false}, $errorBoxOffset); $left = $errorBoxOffset.left; $top = $errorBoxOffset.top; Thanks a lot guys! On 8/28/07, Brandon Aaron [EMAIL PROTECTED] wrote: You can very easily add these helper methods to your own app like this: jQuery.fn.left = function() { return this.offset({scroll:false}).left; }; jQuery.fn.top = function() { return this.offset ({scroll:false}).top; }; -- Brandon Aaron On 8/28/07, Olivier Percebois-Garve [EMAIL PROTECTED] wrote: Okay, I'm doing a lot of jQuery today so please pardon me if I'm sending too much emails here. I'm annoyed with the (otherwise great) dimension plugin because there is no direct way to get the top and left position of an element. So all over my code I have things such as : $errorBoxOffset = {}; element.offset({scroll: false}, $errorBoxOffset); $left = $errorBoxOffset.left; $top = $errorBoxOffset.top; Have I missed something in the dimension doc ? Do you think it would make sense to add such functions to the dimensions plugin ? -Olivier
[jQuery] Re: Why isn't there top() and left() methods in the dimension plugin ?
On Aug 28, 1:59 pm, Olivier Percebois-Garve [EMAIL PROTECTED] wrote: Wow your too fast guys. It seems that I was using offset() the wrong way. $left = element.offset().left; $top = element.offset().top; The only problem with that is you are calling offset twice (which may impact performance). I would do: $offset = element.offset(); $left = $offset.left; $top = $offset.top;