MCPcopy
hub / github.com/layui/layui / getWidthOrHeight

Function getWidthOrHeight

src/modules/jquery.js:6804–6876  ·  view source on GitHub ↗
(elem, dimension, extra)

Source from the content-addressed store, hash-verified

6802 }
6803
6804 function getWidthOrHeight(elem, dimension, extra) {
6805 // Start with computed style
6806 var styles = getStyles(elem),
6807 // To avoid forcing a reflow, only fetch boxSizing if we need it (gh-4322).
6808 // Fake content-box until we know it's needed to know the true value.
6809 boxSizingNeeded = !support.boxSizingReliable() || extra,
6810 isBorderBox =
6811 boxSizingNeeded &&
6812 jQuery.css(elem, 'boxSizing', false, styles) === 'border-box',
6813 valueIsBorderBox = isBorderBox,
6814 val = curCSS(elem, dimension, styles),
6815 offsetProp = 'offset' + dimension[0].toUpperCase() + dimension.slice(1);
6816
6817 // Support: Firefox <=54
6818 // Return a confounding non-pixel value or feign ignorance, as appropriate.
6819 if (rnumnonpx.test(val)) {
6820 if (!extra) {
6821 return val;
6822 }
6823 val = 'auto';
6824 }
6825
6826 // Support: IE 9 - 11 only
6827 // Use offsetWidth/offsetHeight for when box sizing is unreliable.
6828 // In those cases, the computed value can be trusted to be border-box.
6829 if (
6830 ((!support.boxSizingReliable() && isBorderBox) ||
6831 // Support: IE 10 - 11+, Edge 15 - 18+
6832 // IE/Edge misreport `getComputedStyle` of table rows with width/height
6833 // set in CSS while `offset*` properties report correct values.
6834 // Interestingly, in some cases IE 9 doesn't suffer from this issue.
6835 (!support.reliableTrDimensions() && nodeName(elem, 'tr')) ||
6836 // Fall back to offsetWidth/offsetHeight when value is "auto"
6837 // This happens for inline elements with no explicit setting (gh-3571)
6838 val === 'auto' ||
6839 // Support: Android <=4.1 - 4.3 only
6840 // Also use offsetWidth/offsetHeight for misreported inline dimensions (gh-3602)
6841 (!parseFloat(val) &&
6842 jQuery.css(elem, 'display', false, styles) === 'inline')) &&
6843 // Make sure the element is visible & connected
6844 elem.getClientRects().length
6845 ) {
6846 isBorderBox =
6847 jQuery.css(elem, 'boxSizing', false, styles) === 'border-box';
6848
6849 // Where available, offsetWidth/offsetHeight approximate border box dimensions.
6850 // Where not available (e.g., SVG), assume unreliable box-sizing and interpret the
6851 // retrieved value as a content box dimension.
6852 valueIsBorderBox = offsetProp in elem;
6853 if (valueIsBorderBox) {
6854 val = elem[offsetProp];
6855 }
6856 }
6857
6858 // Normalize "" and auto
6859 val = parseFloat(val) || 0;
6860
6861 // Adjust for the element's box model

Callers 1

jquery.jsFile · 0.85

Calls 4

getStylesFunction · 0.85
curCSSFunction · 0.85
nodeNameFunction · 0.85
boxModelAdjustmentFunction · 0.85

Tested by

no test coverage detected