Created
July 4, 2014 18:15
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
s