Download
User Rating: 0/5 ( 0 votes)
Autosize is a small jQuery plugin to allow dynamic resizing of textarea height, so that it grows as based on visitor input.
Compatible with: jQuery 1.7+ in Chrome, Firefox 4+, Safari 5+, Internet Explorer 6+, Opera 11+.
Source: jacklmoore.com
1. INCLUDE JS FILES
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js'></script>
<script src='jquery.autosize.js'></script>
2. HTML
<textarea id='normal'>Not animated.</textarea>
<textarea id='animated'>With CSS transition.</textarea>
3. JAVASCRIPT
$(function(){
$('.normal').autosize();
$('.animated').autosize();
});
4. CSS
.animated {
-webkit-transition: height 0.2s;
-moz-transition: height 0.2s;
transition: height 0.2s;
}
5. SETTINGS
Property |
Default |
Description |
className |
'autosizejs' |
The className property is used to specify a class for the mirrored element, in case it's necessary to explicitly set a style on the mirrored element (see the note about line-height below). |
callback |
false |
A function to call when the textarea is resized. |
append |
"\n" |
By default, an extra newline is appended at the end of the text used in the height calculation. This smooths out the height adjustment when animating. This also avoids an issue with IE10+ briefly causing text to shift immediately before the height is increased. |
Manual Triggering
Autosize has no way of knowing when the value of a textarea has been changed through JavaScript. If you do this, trigger the autosize.resize event immediately after to update the height. Example:
$('#example').val('New Text!').trigger('autosize.resize');
Removing Autosize
Trigger the autosize.destroy event to remove autosize from a textarea element:
$('#example').trigger('autosize.destroy');