textarea高度随内容撑高

(function($){
      $.fn.autoTextarea = function(options) {
            var defaults={
              maxHeight:null,
              minHeight:$(this).height()
            };
            var opts = $.extend({},defaults,options);
            return $(this).each(function() {
              $(this).height($(this)[0].scrollHeight);
              $(this).bind("paste cut keydown keyup focus blur",function(){
                var height,style=this.style;
                this.style.height = opts.minHeight + 'px';
                if (this.scrollHeight > opts.minHeight) {
                  if (opts.maxHeight && this.scrollHeight > opts.maxHeight) {
                    height = opts.maxHeight;
                  } else {
                    height = this.scrollHeight;
                  }
                  style.height = height + 'px';
                }
              });
            });
          };
        })(jQuery);
    $("#textarea").autoTextarea();

posted @ 2018-08-27 13:52  我是前端QQ942031558  阅读(230)  评论(0编辑  收藏  举报