| 104 | |
| 105 | // return the computed value of a CSS property |
| 106 | function curCSS(elem, prop) { |
| 107 | let value, |
| 108 | pixel, |
| 109 | unit, |
| 110 | rvpos = /^(top|bottom)/, |
| 111 | outerProp = ['paddingTop', 'paddingBottom', 'borderTop', 'borderBottom'], |
| 112 | innerHeight, |
| 113 | parent, |
| 114 | i = 4; // outerProp.length |
| 115 | |
| 116 | if (getComputedStyle) { |
| 117 | // FireFox, Chrome/Safari, Opera and IE9+ |
| 118 | value = getComputedStyle(elem)[prop]; |
| 119 | } else if (pixel == elem.style['pixel' + prop.charAt(0).toUpperCase() + prop.slice(1)]) { |
| 120 | // IE and Opera support pixel shortcuts for top, bottom, left, right, height, width |
| 121 | // WebKit supports pixel shortcuts only when an absolute unit is used |
| 122 | value = pixel + 'px'; |
| 123 | } else if (prop === 'fontSize') { |
| 124 | // correct IE issues with font-size |
| 125 | // @see http://bugs.jquery.com/ticket/760 |
| 126 | value = toPx(elem, '1em', 'left', 1) + 'px'; |
| 127 | } else { |
| 128 | // IE 8 and below return the specified style |
| 129 | value = elem.currentStyle[prop]; |
| 130 | } |
| 131 | |
| 132 | // check the unit |
| 133 | unit = (value.match(runit) || [])[2]; |
| 134 | if (unit === '%' && computedValueBug) { |
| 135 | // WebKit won't convert percentages for top, bottom, left, right, margin and text-indent |
| 136 | if (rvpos.test(prop)) { |
| 137 | // Top and bottom require measuring the innerHeight of the parent. |
| 138 | parent = elem.parentNode || elem; |
| 139 | innerHeight = parent.offsetHeight; |
| 140 | while (i--) { |
| 141 | innerHeight -= parseFloat(curCSS(parent, outerProp[i])); |
| 142 | } |
| 143 | value = parseFloat(value) / 100 * innerHeight + 'px'; |
| 144 | } else { |
| 145 | // This fixes margin, left, right and text-indent |
| 146 | // @see https://bugs.webkit.org/show_bug.cgi?id=29084 |
| 147 | // @see http://bugs.jquery.com/ticket/10639 |
| 148 | value = toPx(elem, value); |
| 149 | } |
| 150 | } else if ((value === 'auto' || (unit && unit !== 'px')) && getComputedStyle) { |
| 151 | // WebKit and Opera will return auto in some cases |
| 152 | // Firefox will pass back an unaltered value when it can't be set, like top on a static element |
| 153 | value = 0; |
| 154 | } else if (unit && unit !== 'px' && !getComputedStyle) { |
| 155 | // IE 8 and below won't convert units for us |
| 156 | // try to convert using a prop that will return pixels |
| 157 | // this will be accurate for everything (except font-size and some percentages) |
| 158 | value = toPx(elem, value) + 'px'; |
| 159 | } |
| 160 | return value; |
| 161 | } |