Reputation: 7982
I'm trying to find the best textarea autogrow plugin. I need one which resizes the textarea even when I paste into it. Any idea?
Upvotes: 8
Views: 22563
Reputation: 31839
Auto-expand of text area can be accomplished without plugin. For example:
var change_textarea = function() {
jQuery('#your_textarea').on( 'change keyup keydown paste cut', 'textarea',
function(){
jQuery(this).height(0).height(this.scrollHeight);
}).find( 'textarea' ).change();
}
And do not forget to call the function on document ready:
jQuery(document).ready(function() {
change_textarea();
)};
Upvotes: 0
Reputation: 1222
"I need one which resizes the textarea even when I paste into it"
this method also listen for copy/paste events: https://stackoverflow.com/a/5346855/4481831
I think on modern browsers those events can be replaced with "input" event, but on older browser this method will not work.
Upvotes: 0
Reputation: 3559
Why not use it?? http://plugins.jquery.com/project/autogrowtextarea
Or another updated version of this plugin here: https://github.com/ro31337/jquery.ns-autogrow
Upvotes: 4
Reputation: 265
I used the following method, in jQuery
.
setInterval(function(){
$(name_textarea).css('height', $(name_textarea)[0].scrollHeight+2+'px')
},100);
Try it, you could possibly change the scrollHeight
to obtain the best results.
Upvotes: 2
Reputation: 4100
This is the one I ended up using. Working great so far!
http://www.jacklmoore.com/autosize/
The JQuery Elastic plugin is slow and didn't work for me in IE8.
Upvotes: 4
Reputation: 692
i made another one plugin to do this, check it here: https://github.com/AndrewDryga/jQuery.Textarea.Autoresize
Upvotes: 0
Reputation: 1300
Here is another plug, that also support horizontal growing of text areas:
https://github.com/dgbeck/jquery.autogrow-textarea
It is also based on the "mirror" approach but falls back to simple math in IE 8 and lower, since the mirror approach leads to textareas that grow too quickly in IE <= 8.
Upvotes: -1
Reputation: 11
You can try Advanced Textarea. Download from http://www.jscripts.info
Upvotes: 1