Side navigation
#12313 closed bug (fixed)
Opened August 15, 2012 09:04PM UTC
Closed August 28, 2012 01:00PM UTC
.height() and .width() no longer fall back to CSS if offsetWidth is undefined.
Reported by: | mbaker.pdx@gmail.com | Owned by: | mikesherov |
---|---|---|---|
Priority: | blocker | Milestone: | 1.8.1 |
Component: | css | Version: | 1.8.0 |
Keywords: | Cc: | mikesherov | |
Blocked by: | Blocking: |
Description
offsetWidth and offsetHeight are undefined for SVG elements in Firefox and IE 9. jQuery used to fall back to computed, then uncomputed CSS in this case, but that no longer happens after the following commit:
https://github.com/jquery/jquery/commit/5376a809c0d2bee4b7872847c2821e458dfdcc3b
In "getWidthOrHeight":
// Start with offset property var val = name === "width" ? elem.offsetWidth : elem.offsetHeight, i = name === "width" ? 1 : 0, len = 4; if ( val > 0 ) { //... } // Fall back to computed then uncomputed css if necessary val = curCSS( elem, name ); //...
"val > 0" failed if offsetWidth or offsetHeight were undefined, so fallback would always occur.
In 5376a809 the condition was changed to the following:
if ( val <= 0 ) { // Fall back to computed then uncomputed css if necessary val = curCSS( elem, name ); //... }
"undefined" will never be <= 0. I think it's possible the former conditional logic caught the "undefined" case by accident. If not, the intent of the conditional logic was not clear if it was supposed to handle "undefined" (but may have saved bytes).
Test case:
This will show NaNpx for height and width in Firefox and IE9, 200 in Chrome. The assertion in the console will also fail.
It looks like a bug for offsetWidth/Height being undefined on SVG elements in Firefox has been filed:
Attachments (0)
Change History (4)
Changed August 21, 2012 12:39AM UTC by comment:1
cc: | → mikesherov |
---|---|
component: | unfiled → css |
milestone: | None → 1.8.1 |
priority: | undecided → blocker |
status: | new → open |
Changed August 21, 2012 12:58AM UTC by comment:2
owner: | → mikesherov |
---|---|
status: | open → assigned |
TIL that:
undefined < 0 // false undefined > 0 // false undefined == 0 // false !undefined // true
PR to come shortly.
Mike, looks like it should be fixable if we tweak the conditional?