Last active
August 29, 2015 14:03
-
-
Save haggen/18645f9adf0ea162bab4 to your computer and use it in GitHub Desktop.
Auto size (height) for <textarea>
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
;(function() { | |
var sham = $('<pre></pre>'); | |
sham.appendTo('body'); | |
$(document).on('input change focus', 'textarea', function() { | |
var textarea = $(this); | |
sham.css('width', textarea.outerWidth()); | |
sham.text(this.value + ' '); | |
sham.attr('class', 'textarea-sham ' + textarea.attr('class')); | |
textarea.css('height', sham.outerHeight()); | |
}); | |
})(); |
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
// Add this to your stylesheet (SCSS required) | |
.textarea-sham { | |
@extend textarea; | |
display: none; | |
height: auto; | |
white-space: pre-line; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment