打字和跑进页底时如何防止textarea跳舞?:JQuery/CSS

fat*_*ael 5 html javascript css jquery

我一直在输入自动调整大小的textarea;

当文本进入页面底部并继续输入时;

我发现在每个按键或键盘和文本上跳起来像地狱的页面都会进入页面底部(为此我需要向下滚动以检查发生了什么).如何防止页面跳舞和文本进入底部?

JS小提琴:https://jsfiddle.net/osbnnbxa/

浏览器:IE10(也发现在Firefox中跳舞很少;但是客户端使用IE10所以只需要处理它)

HTML:

<div>
 <div>
  <br><br> &nbsp;&nbsp;
    <textarea class="normal" name="myarea" id="myarea" style="height: 100px; overflow-y: hidden;"></textarea>
  </div>
</div> 
<input type="button" class="butt" value="ehehehhe" />
Run Code Online (Sandbox Code Playgroud)

JQuery的:

var myquery = {
  autoHeight: function(e) {
  $(e).css({
  'height': 'auto',
  'overflow-y': 'hidden'
 }).height(e.scrollHeight);
},
init: function() {
setTimeout(function() {
  $('textarea').each(function() {
    myquery.autoHeight(this);
  }).on('input', function() {
    myquery.autoHeight(this);
  });
}, 200);
$("textarea").keypress(function(e) {
   $(".butt").focus();    
   $(this).focus();    
});
  }

};

$(myquery.init);
Run Code Online (Sandbox Code Playgroud)

更新:客户说没有定义textarea的最大高度.让它随着文本的增加而流动.

And*_*man 1

好吧,我知道你说让文本区域流动,但我真的很喜欢这个解决方案。在你的小提琴中,它让文本区域增长到接近视口的底部并停止所有的舞蹈。希望这是一个合理的妥协。修改后的小提琴在这里

textarea {
  max-height: 85vh;
}
Run Code Online (Sandbox Code Playgroud)