New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
width(), height(), etc. shouldn't round #1724
Comments
Author: rwaldron 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. |
Author: bzbarsky 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). |
Author: mikesherov Boris, what do you suggest here, to just stop rounding if a fraction is returned? |
Author: dmethvin #12870 is a duplicate of this ticket. |
Author: mikesherov #12373 is a duplicate of this ticket. |
Author: mikesherov 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 ;-) |
Author: mikesherov 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. |
Author: mikesherov From Boris: https://bugzilla.mozilla.org/show_bug.cgi?id=825607#c5
|
Author: mikesherov 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: 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. |
Author: mikesherov Oh, and IE10 works right too. |
Author: dmethvin #14039 is a duplicate of this ticket. |
Author: dmethvin #14556 is a duplicate of this ticket. |
Author: dmethvin 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. |
I'm going to mark this for potential inclusion in the 3.0 release, it might be the best place to try a breaking change like this. |
@mikesherov Assigning to myself but if you want to do it, please re-assign back (and notify me plz). |
I would like to add, since I don't see it mentioned anywhere in here, that .css("height") and .css("width") are also rounding values. Here's a fiddle: http://jsfiddle.net/Marventus/L16gmjuz/ |
Yes, that's caused by the same code. Lines 353 to 382 in 002240a
and: Lines 71 to 152 in 002240a
That's quite a lot of code, btw... Original issue mentioned hidden elements as well: http://bugs.jquery.com/ticket/7225 This code also works around a number of box sizing IE bugs. |
Hi guys. What's the state of this issue? Will it be fixed in jQuery 3? |
@AurelioDeRosa Well, it's on the v3.0 milestone at least. :) |
@arthurvr I saw the label as well but this doesn't reply to my question. |
@AurelioDeRosa It's planned for 3.0 and I'm assigned. I just need to get to it. :) I'll try to do it soon, I'd like it to land before we tag the first beta. |
PR: #2439. Feedback welcome. |
|
I've added a note to the blog post. |
As reported in #2889, Chrome is deprecating |
Originally reported by john at: http://bugs.jquery.com/ticket/9628
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.
Issue reported for jQuery 1.6.1
The text was updated successfully, but these errors were encountered: