Bug Tracker

Ticket #984 (closed bug: invalid)

Opened 2 years ago

Last modified 2 months ago

$(element).width() & $(element).height() functions return incorrect values

Reported by: elemerz Assigned to: anonymous
Type: bug Priority: minor
Milestone: 1.1.2 Component: core
Version: 1.1.1 Keywords: Layout Manager
Cc: Needs:

Description

$(element).width() & $(element).height() functions return incorrect values. I rewrote the prototype 1.5.0 -based [RUZEE layout Manager|http://www.ruzee.com/blog/ruzeelayoutmanager/] for jQuery. I needed to get the dimensions of an element, in form of a hash like: {width:widthValue,height:heightValue}. I used: {width:$(element).width(), height:$(element).height()} in the jQuery version. I noticed that these two functions (width(), and height()) do not return the same values like Element.getDimensions(element) used by prototype. My jQuery -based rewritten version of the above mentioned LayoutManager? does not render correctly because of these differences. To see in action what I'm talking about, set the useJQueryDimensions variable inside of lm.jquery.js file in the attachment. Thanx in advance,

Elemér. In the attachment you can find

Attachments

BugReport.zip (18.0 kB) - added by elemerz 2 years ago.
Layout Manager based on jQuery.

Change History

Changed 2 years ago by elemerz

Layout Manager based on jQuery.

Changed 2 years ago by alexo

This ticket is related to core component, not ajax...

Changed 2 years ago by john

  • priority changed from major to minor
  • component changed from ajax to core

I'm not entirely sure what I'm supposed to be seeing - but I did notice that you subtract the padding and border widths from the height/width - jQuery already does this. The .height() and .width() returned by jQuery do not include those numbers, and are stable across browsers.

Additionally, you may want to look into the Dimensions plugin, which will reduce the size of your plugin by about 90%, it looks like.

http://dev.jquery.com/browser/trunk/plugins/dimensions/dimensions.js?format=txt

Changed 2 years ago by brandon

  • status changed from new to closed
  • resolution set to invalid

As John mentioned, the jQuery width and height methods return the actual computed CSS width and height. If you want the offset width (includes padding and border) you should use the dimensions plugin outerWidth method (it also accounts for if an element is display: none).

Also just a note ... you can pass the css method numbers and it will append the "px" for you.

Note: See TracTickets for help on using tickets.