javascript - Auto-adjusting textarea to be the same height as inner-text onkeydown -
i'm trying auto adjust height of textarea onkeydown, it's working partially. when you're typing text textarea, auto-adjust height of textarea per new line of text, want. when you're backspacing text, auto-adjust height of textarea per character-backspaced when you're on last 5 characters of every last line. doing wrong?
#textarea { overflow: hidden; } <textarea id = 'textarea' onkeydown = "adjust()"></textarea> <script> function adjust() { document.getelementbyid("textarea").style.height = document.getelementbyid("textarea").scrollheight+'px'; } //end of function adjust() </script>
create textarea:
<textarea id="textarea" onkeyup="inputadjust(this)"></textarea> then create function auto height
<script> function inputadjust(o) { o.style.height = "1px"; o.style.height = (25+o.scrollheight)+"px"; } </script> now +25px, can change it.
example: https://jsfiddle.net/urp4nbxf/1/
Comments
Post a Comment