red-devil red-devil - 1 year ago 155
AngularJS Question

Resizable Textarea that resizes in the up direction (No Jquery)

I need to make Html Textarea input to auto-resize in the UP direction with increase in the content. Check out this fiddle which auto-resizes Textarea in the opposite direction.

<!DOCTYPE html>
<title>autoresizing textarea</title>
<style type="text/css">
textarea {
border: 0 none white;
overflow: hidden;
padding: 0;
outline: none;
background-color: #D0D0D0;
resize: none;
<script type="text/javascript">
var observe;
if (window.attachEvent) {
observe = function (element, event, handler) {
element.attachEvent('on'+event, handler);
else {
observe = function (element, event, handler) {
element.addEventListener(event, handler, false);
function init () {
var text = document.getElementById('text');
function resize () { = 'auto'; = text.scrollHeight+'px';
/* 0-timeout to get the already changed text */
function delayedResize () {
window.setTimeout(resize, 0);
observe(text, 'change', resize);
observe(text, 'cut', delayedResize);
observe(text, 'paste', delayedResize);
observe(text, 'drop', delayedResize);
observe(text, 'keydown', delayedResize);

<body onload="init();">
<textarea rows="1" style="height:1em;" id="text"></textarea>

Any suggestions to get this done.

PS: Can't use Jquery. Angularjs can be used if required.

Answer Source

I am slightly puzzled as to what you are trying to do. I am assuming there will be some space for the textarea to expand into above it? If that is the case, it is easy. No scripting required...

put the text area inside a div and assign it the following css (for example):

height: 200px;
vertical-align: bottom;
display: table-cell;

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download