我已经实现了一个标准的jQuery自动增长/扩展textarea插入到iPhone我的web应用。它工作正常,除了两个问题(下面列出)。首先,请允许我强调我已经尝试过使用Google搜索并尝试使用不同的教程,并得出这样的结论,即这是对我的需求最好的一个。jQ自动增长文本区域问题 - 延迟扩展和填充问题
问题1.延迟textarea onKeyUp的扩展。怎么样?功能拓展上称为KEYUP:
$(this).keyup(update);
由于我使用CSS3动画(-webkit-过渡),以动画的扩展和自网站/“应用程序”是专为iPhone手机,我需要延迟这个动作说500毫秒,这样打字就不会因为这个而滞后。我已经尝试了不同的解决方案,如setTimeOut在代码的不同部分,甚至延迟等,但它不起作用。期。
问题2:textarea上的填充会导致它随机扩展,并且应该是它的两倍。
padding:10px 10px;
这是一个已知的问题 - 我知道,但到目前为止,它好像知道的人还没有想出如何正确处理它。删除填充使一切工作正常。没有建议我使用另一个插件或只是删除填充,如何更改代码以使其可以使用填充?
JS代码HANDELING扩张:
(function($) {
/*
* Auto-growing textareas; technique ripped from Facebook
*/
$.fn.autogrow = function(options) {
this.filter('textarea').each(function() {
var $this = $(this),
minHeight = $this.height(),
lineHeight = $this.css('lineHeight');
var shadow = $('<div></div>').css({
position: 'absolute',
top: -10000,
left: -10000,
width: $(this).width(),
fontSize: $this.css('fontSize'),
fontFamily: $this.css('fontFamily'),
lineHeight: $this.css('lineHeight'),
resize: 'none'
}).appendTo(document.body);
var update = function() {
var val = this.value.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/&/g, '&')
.replace(/\n/g, '<br/>');
shadow.html(val);
$(this).css('height', Math.max(shadow.height() + 15, minHeight));
$("#guestInfoNameLable").css('height', Math.max(shadow.height() + 15, minHeight));
}
var fix = function() {
var val = this.value.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/&/g, '&')
.replace(/\n/g, '<br/>');
shadow.html(val);
$(this).css('height', minHeight);
$("#guestInfoNameLable").css('height', minHeight);
}
$(this).keyup(update);
$(this).change(fix);
//$(this).change(update).keyup(update).keydown(update);
update.apply(this);
});
return this;
}
})(jQuery);
HTML表单:
<div class="guestInfoLabel" id="guestInfoNameLable">guest</div>
<textarea id="guestInfoName" autocomplete="off" autocorrect="off"></textarea>