1 (function ($) {
2 $.fn.autoTextarea = function (options) {
3 var defaults = {
4 maxHeight: null,
5 minHeight: $(this).height()
6 };
7 var opts = $.extend({}, defaults, options);
8 return $(this).each(function () {
9 $(this).bind("paste cut keydown keyup focus blur", function () {
10 var height, style = this.style;
11 this.style.height = opts.minHeight + 'px';
12 if (this.scrollHeight > opts.minHeight) {
13 if (opts.maxHeight && this.scrollHeight > opts.maxHeight) {
14 height = opts.maxHeight;
15 style.overflowY = 'scroll';
16 } else {
17 height = this.scrollHeight;
18 style.overflowY = 'hidden';
19 }
20 style.height = height + 'px';
21 }
22 });
23 });
24 };
25 })(jQuery);
26 $("textarea#txt_show").autoTextarea({
27 maxHeight: 2000,
28 minHeight: 80
29 });