diff --git a/jquery.autosize.js b/jquery.autosize.js index a40ce94..8b31a7e 100644 --- a/jquery.autosize.js +++ b/jquery.autosize.js @@ -101,13 +101,14 @@ $.each(['paddingLeft', 'paddingRight', 'borderLeftWidth', 'borderRightWidth'], function(i,val){ width -= parseInt(style[val],10); }); - - mirror.style.width = width + 'px'; } - else { + if (!style || width == 0) { // window.getComputedStyle, getBoundingClientRect returning a width are unsupported and unneeded in IE8 and lower. - mirror.style.width = Math.max($ta.width(), 0) + 'px'; + // In some situations, if the element is offscreen, then the above approach will result in 0 width, + // but the approach below works. + mirror.style.width = Math.max($ta.width(), 0); } + mirror.style.width = width + 'px'; } function initMirror() { @@ -247,4 +248,4 @@ adjust(); }); }; -}(window.jQuery || window.$)); // jQuery or jQuery-like library, such as Zepto \ No newline at end of file +}(window.jQuery || window.$)); // jQuery or jQuery-like library, such as Zepto