Skip to content

Instantly share code, notes, and snippets.

@AMKohn
Created July 4, 2014 18:15
Show Gist options
  • Save AMKohn/ade4dad8ae0a599b90f0 to your computer and use it in GitHub Desktop.
Save AMKohn/ade4dad8ae0a599b90f0 to your computer and use it in GitHub Desktop.
Textarea autosizer modified from Shog9's answer on SO: http://stackoverflow.com/a/7875/900747
var autosize = function(e) {
var area = e.currentTarget,
ch = area.clientHeight, // These should be cached as much as possible since this is triggered on keyup
sh = area.scrollHeight;
if (ch == sh) {
area.style.height = "30px";
// Recache them
var ch = area.clientHeight,
sh = area.scrollHeight;
}
var adjustedHeight = Math.max(sh, ch);
if (adjustedHeight > ch) {
area.style.height = adjustedHeight + "px";
}
};
@yorkcarol
Copy link

yorkcarol commented Mar 26, 2024

s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment