[转]autoTextarea-文本框根据输入内容自适应高度
2011-08-08 15:54
591 查看
在玩微博的时候我们可能会注意到一个细节就是不管是新浪微博还是腾讯微博在转发和评论的时候给你的默认文本框的高度都不会很高,这可能是版面的限制和用户通常只转播或者评论一个短句有关。但是当你输入超过一行文字的时候,文本框的高度就自动撑高了,大大改善了体验,这样用户就可以看到全部的文字。不用再去拖动文本框的滚动条。如图:
新浪微博:@feiwen8772(我的新浪微博,顺便做个广告,^_^)
腾讯微博:@feiwen8772(我的腾讯微博,顺便做个广告,^_^)
这些在平时的项目中挺实用的,所以抽空封装了一个文本框根据输入内容自适应高度的插件-autoTextarea:
调用:
查看demo:http://www.css88.com/demo/autoTextarea/
转自《【jQuery插件】autoTextarea-文本框根据输入内容自适应高度》
新浪微博:@feiwen8772(我的新浪微博,顺便做个广告,^_^)
腾讯微博:@feiwen8772(我的腾讯微博,顺便做个广告,^_^)
这些在平时的项目中挺实用的,所以抽空封装了一个文本框根据输入内容自适应高度的插件-autoTextarea:
01 | ( function ($){ |
02 | $.fn.autoTextarea = function (options) { |
03 | var defaults={ |
04 | maxHeight: null , //文本框是否自动撑高,默认:null,不自动撑高;如果自动撑高必须输入数值,该值作为文本框自动撑高的最大高度 |
05 | minHeight:$( this ).height() //默认最小高度,也就是文本框最初的高度,当内容高度小于这个高度的时候,文本以这个高度显示 |
06 | }; |
07 | var opts = $.extend({},defaults,options); |
08 | return $( this ).each( function () { |
09 | $( 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); |
1 | $( ".chackTextarea-area" ).autoTextarea({maxHeight:220}); |
转自《【jQuery插件】autoTextarea-文本框根据输入内容自适应高度》
相关文章推荐
- jquery/js实现文本框根据输入内容input,textarea自适应高度
- textarea自动换行,且文本框根据输入内容自适应高度
- 文本框根据输入内容自适应高度
- jQuery插件——autoTextarea-文本框根据输入内容自适应高度
- Jquery实现 TextArea 文本框根据输入内容自动适应高度
- Jquery实现 TextArea 文本框根据输入内容自动适应高度
- 【jQuery插件】autoTextarea-文本框根据输入内容自适应高度
- 【jQuery插件】autoTextarea-文本框根据输入内容自适应高度的实例页面
- 文本框根据输入内容自适应高度的代码
- Jquery实现textarea根据文本内容自适应高度
- Textarea根据内容自适应高度
- Javascript 文本框textarea高度随内容自适应增长收缩
- 模拟新浪微博评论textarea输入框随着输入内容增多输入框高度自适应
- 基于JQ 根据输入内容自适应输入框高度 支持输入增高 渲染时设置高度和内容一致
- 关于textView根据输入内容自适应高度
- js实现textarea高度根据内容自适应
- js实现textarea高度根据内容自适应
- jQuery实现textarea高度根据内容自适应
- Textarea 高度自适应 根据内容自适应高度