Skip to content

Instantly share code, notes, and snippets.

@mofodox
Created October 4, 2015 16:42
Show Gist options
  • Save mofodox/f79bf65bb53ecde2ea0b to your computer and use it in GitHub Desktop.
Save mofodox/f79bf65bb53ecde2ea0b to your computer and use it in GitHub Desktop.
KdWbWE
<textarea rows="1"></textarea>
var textarea = document.querySelector('textarea');
textarea.addEventListener('keydown', autosize);
function autosize(){
var el = this;
setTimeout(function(){
el.style.cssText = 'height:auto; padding:0';
// for box-sizing other than "content-box" use:
// el.style.cssText = '-moz-box-sizing:content-box';
el.style.cssText = 'height:' + el.scrollHeight + 'px';
},0);
}
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
textarea {
/*position: absolute;*/
border: none;
/*min-width: 50%;*/
font-size: 20px;
line-height: 28px;
padding: 25px;
width: 80%;
display: block;
margin-top: 15px;
margin-left: auto;
margin-right: auto;
resize: none;
overflow: hidden;
}
textarea:focus {
outline: none;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment