Skip to main content

Bug Tracker

Side navigation

#9628 closed bug (migrated)

Opened June 20, 2011 09:38PM UTC

Closed October 20, 2014 10:49PM UTC

width(), height(), etc. shouldn't round

Reported by: john Owned by: mikesherov
Priority: low Milestone: None
Component: css Version: 1.6.1
Keywords: Cc:
Blocked by: Blocking:
Description

Right now we're rounding off the answers from width(), height(), etc. to the nearest pixel - this makes it hard to do good positioning of elements (especially for animations). For example if you have 3 items that are width 33% inside of a 100px element we're returning 33px for each element. Theoretically an animation method might be able to return a more interesting result if they know that there are extra fractional-numbers getting rounded off.

I got a report on this directly from Mozilla but I agree with them that this particular change makes it hard to get to good numbers.

See also: #3239.

Attachments (0)
Change History (19)

Changed June 20, 2011 09:38PM UTC by john comment:1

component: unfiledcss
priority: undecidedlow

Changed June 27, 2011 04:35PM UTC by addyosmani comment:2

status: newopen

Changed July 12, 2011 04:09PM UTC by rwaldron comment:3

resolution: → wontfix
status: openclosed

For normalization purposes, jQuery core will maintain round pixel value returns, however you can easily write a cssHook to return the width/height in any value format that you prefer.

Changed November 19, 2012 03:56PM UTC by bzbarsky comment:4

Just to be clear, this bug makes width() completely useless for layout calculations in UAs that do subpixel layout: you compute some widths that look like they should fit in a container, but in fact they don't.

People are running into this all the time in UAs that in fact do subpixel layout (e.g. not WebKit).

Changed November 19, 2012 05:13PM UTC by mikesherov comment:5

Boris, what do you suggest here, to just stop rounding if a fraction is returned?

Changed November 19, 2012 05:33PM UTC by mikesherov comment:6

resolution: wontfix
status: closedreopened

Changed November 19, 2012 05:44PM UTC by mikesherov comment:7

milestone: 1.next1.9
owner: → mikesherov
status: reopenedassigned

Changed November 21, 2012 06:15PM UTC by dmethvin comment:8

#12870 is a duplicate of this ticket.

Changed December 13, 2012 07:00AM UTC by mikesherov comment:9

#12373 is a duplicate of this ticket.

Changed December 29, 2012 10:56PM UTC by mikesherov comment:10

bzbarsky, if we could get FF to return floats for offsetWIdth and offsetHeight, that would solve this is. In fact, jQuery doesn't use the getComputedStyle().height for calculations. It uses offsetHeight, then subtracts/adds padding, border, margin as necessary. Perhaps I can file a bug with you about it ;-)

Changed December 31, 2012 04:04PM UTC by mikesherov comment:11

bzbarsky, reported to FF here: https://bugzilla.mozilla.org/show_bug.cgi?id=825607

I might take a stab at ditching offsetWidth/offsetHeight for jQuery 2.0 once oldIE codepaths are gone, but this would be fixed automatically if offsetWidth/Height stopped rounding.

Changed December 31, 2012 05:52PM UTC by mikesherov comment:12

From Boris: https://bugzilla.mozilla.org/show_bug.cgi?id=825607#c5

Just don't use offset*. Use getBoundingClientRect."

Changed December 31, 2012 06:52PM UTC by mikesherov comment:13

SO, the good news is that for FF, Chrome, Safari, and Opera , getBoundingClientRect work great, reporting subpixel values when appropriate, and containing a "width" property:

http://jsfiddle.net/7MMhB/4/

However, the bad news is, IE9 reports "2" (as opposed to 3 for offsetWidth), IE<9 reports a TextRectangle object with no width property. Sigh.

If we truly want to get all subpixely, either we now see if we can drop offsetWidth altogether, or we do a feature detect for subpixely getBoundingRectClient, and use that when we can.

Changed December 31, 2012 06:54PM UTC by mikesherov comment:14

Oh, and IE10 works right too.

Changed March 01, 2013 05:51PM UTC by dmethvin comment:15

milestone: 1.9None

Changed June 23, 2013 04:11PM UTC by dmethvin comment:16

#14039 is a duplicate of this ticket.

Changed December 08, 2013 03:36PM UTC by dmethvin comment:17

#14556 is a duplicate of this ticket.

Changed June 19, 2014 04:46PM UTC by dmethvin comment:18

Ref: https://codereview.chromium.org/340903002/

Still, jQuery may be in a better position to do this, since the site gets to choose whether it wants to upgrade to a newer jQuery. It's a question of whether there are a lot of popular plugins that would break with fractional widths and heights.

Changed October 20, 2014 10:49PM UTC by m_gol comment:19

resolution: → migrated
status: assignedclosed