I'm trying to find the best textarea autogrow plugin. I nee开发者_如何学Cd one which resizes the textarea even when I paste into it. Any idea?
Elastic is a very good one, and it handles CTRL + V cases too.
You can visit the website and try out a demo.
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
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.
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.
You can try Advanced Textarea. Download from http://www.jscripts.info
- Auto-Height Textarea
- Returns Plain Text and HTML Content
- Automatic URL and Email recognition
- HTML Tags Filter
i made another one plugin to do this, check it here: https://github.com/AndrewDryga/jQuery.Textarea.Autoresize
"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.
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();
)};
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.
精彩评论