Many of the front-end development of friends may encounter textarea input box height can not automatically change with the user's input, today's niche also encountered, and through the information on the network to solve the problem, so the solution is affixed to make a memo.
Directiveapp.directive (' Autoheight ', function () { function autoheight (elem) { elem.style.height = ' auto '; elem.scrolltop = 0; Anti-jitter elem.style.height = elem.scrollheight + ' px '; } return { scope: {}, link:function (scope, ele, attrs) { var Oriele = $ (ele). Get (0); $ (Oriele). focus (); $ (Oriele). bind (' KeyUp click ', Function (e) { autoheight ($ (this). Get (0)); }); var timer = setinterval (function () { if ($ (Oriele). Val ()) { autoheight (oriele); Clearinterval (timer);}};} );
Html Code: <textarea auto-height></textarea>
No, I hope you'll forgive me.
Angular Textarea Height Automatic change