Created
October 17, 2016 05:04
-
-
Save Boorj/1e4402eccddd55bb653db57f43102e73 to your computer and use it in GitHub Desktop.
Assigns auto height fitting for any <textarea/> on page
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
| //requires _.throttle and jquery, but dependency could be removed | |
| (function() { | |
| var AutoGrowTextArea; | |
| AutoGrowTextArea = function(e) { | |
| var textField; | |
| textField = e.target; | |
| if (textField.clientHeight < textField.scrollHeight) { | |
| textField.style.height = textField.scrollHeight + 'px'; | |
| if (textField.clientHeight < textField.scrollHeight) { | |
| textField.style.height = textField.scrollHeight * 2 - textField.clientHeight + 'px'; | |
| } | |
| } | |
| }; | |
| return $('textarea').keyup(_.throttle(AutoGrowTextArea, 900)); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment