js代码如下:

 /*
*高度自动增长的文本框
*/
Ext.define('ux.TextArea', {
extend: 'Ext.field.TextArea',
xtype: 'autoTextArea',
config: {
clearIcon: false,
//不配置maxRows和lineHeight则没有增长限制
maxRows: 3,
lineHeight: 29
},
initialize: function () {
var me = this;
me.callParent(arguments);
me.adjustHeight = Ext.Function.createBuffered(function () {
var textAreaEl = me.getComponent().input;
if (textAreaEl) {
var scrollHeight = textAreaEl.dom.scrollHeight,
height;
//根据条件调整高度
if (!me.maxHeight || (me.maxHeight > scrollHeight)) {
height = scrollHeight;
} else {
height = me.maxHeight;
}
textAreaEl.dom.style.height = 'auto';
textAreaEl.dom.style.height = height + "px";
}
}, 200, me);
me.on({
scope: me,
keyup: 'adjustHeight',
change: 'adjustHeight',
painted: 'initHeight'
});
},
//初始化高度
initHeight: function () {
var me = this,
lingHeight = me.getLineHeight(),
maxRows = me.getMaxRows();
//如果有设置lineHeight和maxRows会产生一个最高高度
console.log(lingHeight, maxRows); if (lingHeight && maxRows) {
me.maxHeight = lingHeight * maxRows;
}
},
//重新初始化
reset: function () {
var me = this,
textAreaEl = me.getComponent().input;
if (textAreaEl && me.getValue().length==0) {
textAreaEl.dom.style.height = 'auto';
textAreaEl.dom.style.height = me.getLineHeight() + "29px";
}
}
});

css:

 /*#region textarea */
.x-field-textarea .x-form-field {
line-height:29px;
min-height:29px;
height:34px;
overflow-y:hidden;
padding:0.2em 0 0 0.2em;
border-radius:6px;
}
.x-field-textarea {
min-height:;
border-radius:6px;
}
.x-field-textarea .x-field-input {
padding-right:0 !important;
}
/*#endregion*/

使用示例:

                 flex: 3,
itemId: 'textArea',
xtype: 'autoTextArea',
placeHolder: '说两句',
margin: '10px 15px'

sencha touch 可自动增长高度TextArea的更多相关文章

  1. sencha touch Carousel 自动切换

    代码是在网上找的,忘记原出处了 /** * 跑马灯自动切换 */ Ext.define('ux.RotatingCarousel', { extend: 'Ext.carousel.Carousel' ...

  2. sencha touch JsonP 自动提示消息 masked

    //公用类 Ext.define('app.util', { alternateClassName: 'util', statics: { /*为Ext.Viewport添加一个消息提示组件(需要初始 ...

  3. 【翻译】使用Sencha Touch开发Google Glass应用程序

    原文:Developing for Google Glass with Sencha Touch 作者:Ross Gerbasi Ross Gerbasi is a Senior Engineer a ...

  4. textarea 实现高度自动增长

    有时候希望textarea 能够自动调整高度来适应输入的内容 网上看到了很多解决方案,比如动态创建一个隐藏的div,当用户输入的时候将textarea的内容绑定到div,由于div的高度会自动撑开,因 ...

  5. Jquery实现 TextArea 文本框根据输入内容自动适应高度

    原文 Jquery实现 TextArea 文本框根据输入内容自动适应高度 在玩微博的时候我们可能会注意到一个细节就是不管是新浪微博还是腾讯微博在转发和评论的时候给你的默认文本框的高度都不会很高,这可能 ...

  6. sencha touch textarea 手机上不显示滚动条,且不能滚动

    最近在项目中发现 sencha touch 中的 textarea 在手机上不显示滚动条,也不能滚动. 在浏览器中之所以能显示滚动条滚动,那是浏览器为 textarea 添加的滚动条. 但在手机中是不 ...

  7. HTML的TextArea标记跟随文本内容自动设置高度

    js <textarea name="textarea" id="textarea" style='overflow-y: hidden;height:2 ...

  8. 设置HTML的TextArea标记跟随文本内容自动设置高度

    写内容的时候用的是textarea来写,可以换行,然后预览页面也要显示是换行才行,所以预览页面还是要用textarea来显示, 样式去掉边框,不可以拉伸,不可编辑 // html <textar ...

  9. Android环境配置Sencha Touch

    转自http://www.phonegap100.com/portal.php?mod=view&aid=19 作为你开发的一部分,为安卓设备开发的 Sencha Touch框架应该在安卓虚拟 ...

随机推荐

  1. iOS:DKLiveBlur

    https://github.com/kronik/DKLiveBlur Sources of DKLiveBlur and Demo app to show live blur effect sim ...

  2. windows使用技巧和工具(后面可能更新linux)

    *:希望广大网友有什么建议或者好的用法工具.也能够在以下评论. 希望这是一个能够让我们更好工作起来的帖子. 工作也能舒适和开心呢. 想着好久没写过博客了吧.今天就写一篇关于windows的使用的吧.我 ...

  3. datetimerangepicker配置及默认时间段展示

    <script type="text/javascript"> $(document).ready(function (){ //时间插件 $('#reportrang ...

  4. Adobe超分辨率算法:SRNTT

    论文:Image Super-Resolution by Neural Texture Transfer 论文链接:https://arxiv.org/abs/1903.00834 项目地址:http ...

  5. 总结的比较好的OpenGL教程

    OpenGL Programming Guide(红宝书) http://www.glprogramming.com/red/ OpenGL Reference Manual(蓝宝书) http:// ...

  6. ActiveMq持久化数据

    A:持久化为文件 这个你装ActiveMQ时默认就是这种,只要你设置消息为持久化就可以了.涉及到的配置和代码有 <persistenceAdapter> <kahaDB direct ...

  7. activeMq的helloword

    http://blog.csdn.net/clj198606061111/article/details/38236679 点对点的同步消息模型 http://blog.csdn.net/jiuqiy ...

  8. 既使用maven又使用lib下的Jar包

    maven 使用本地包 lib jar包 依赖一个lib目录 解决方法: # 把本地的lib加入maven编译时的依赖路径 From:http://blog.chinaunix.net/uid-231 ...

  9. 使用pyinotify实现加强版的linux tail -f 命令,并且对日志类型的文本进行单独优化着色显示。

    tail -f命令不能自动切换切片文件,例如日志是每100M生成一个新文件,tail -f不能自动的切换文件,必须关闭然后重新运行tail -f 此篇使用pyinotify,检测文件更新,并实现tai ...

  10. [Object Tracking] Identify and Track Specific Object

    Abstract—Augmented Reality (AR) has become increasingly popular in recent years and it has a widespr ...