Created
May 30, 2019 08:43
-
-
Save alexwebgr/7cfcb0a8fb5d39fef70caaf5c02ef9a6 to your computer and use it in GitHub Desktop.
resize a textarea as you type
This file contains hidden or 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
$("textarea.growable") | |
.on('keyup paste input', function () { | |
let self = $(this); | |
let offset = self.innerHeight() - self.height(); | |
if (self.innerHeight() < this.scrollHeight) { | |
//Grow the field if scroll height is smaller | |
self.height(this.scrollHeight - offset); | |
} else { | |
//Shrink the field and then re-set it to the scroll height in case it needs to shrink | |
self.height(1); | |
self.height(this.scrollHeight - offset); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment