Textarea auto expand

Hi, I have this to automatically decrypt textarea jquery code and currently it works somehow there other than Google Chrome.

The problem is that I added a style add: 3px to the text field, whenever I enter something into the field, it will increase the height. If I remove the style debugging, it will work beautifully.

The test is here: http://jsfiddle.net/JkxgB/ (use Google Chrome for testing)

I was trying to understand why, I would be grateful if anyone could shed light here. Thanks in extended.

+4
source share
2 answers

I recommend you use this plugin instead:

http://plugins.jquery.com/project/TextAreaResizer

StackOverflow uses this plugin for its text fields! Should I talk more?

Hope this helps. Greetings

PS: Or you can use the autoload plugin

+2
source

So sad that you asked 4 years ago, and I just saw it.

The problem arises because the scrollHeight property returns the entire height of the element in pixels; including registration, but not border, scroll bar or margin. (At least in Chrome, IE, and Firefox, these are the three that I tested).

Link: Element Scroll Height

So, I changed line 17 in your Jsfiddle as shown below and the problem is resolved.

 var h = Math.max(e.expandMin, Math.min(e.scrollHeight - 6, e.expandMax)); 
0
source

All Articles