Javascript
textarea 동적으로 resizing 하기
진태우
2018. 7. 20. 11:21
// html code
<textarea data-autoresize rows="2"></textarea>
// javascript code
jQuery.each(jQuery('textarea[data-autoresize]'), function() {
var offset = this.offsetHeight - this.clientHeight;
var resizeTextarea = function(el) {
jQuery(el).css('height', 'auto').css('height', el.scrollHeight + offset);
};
jQuery(this).on('keyup input', function() { resizeTextarea(this); }).removeAttr('data-autoresize');
});
// css code
textarea {
box-sizing: border-box;
resize: none;
}
리사이징이 너무 잘되도록 어떤 외쿡 형님이 작성해놔서 숟가락만 얹었다....