web123456

textarea adaptive height

$(document).on('input propertychange', 'textarea', function () { this.rows =1 // Set rows to 1 first, ‘You can try to delete text without setting it will change the line height? var text_height = $(this).height() // Get the height occupied by the textarea tag var padding_top_and_bottom = $(this).innerHeight() - text_height // Calculate the height occupied by padding var rows = (this.scrollHeight - padding_top_and_bottom ) / text_height // Calculate the number of rows this.rows = rows // Change the number of lines of textarea })