tag:blogger.com,1999:blog-11300808.post2823304741558926312..comments2026-04-16T00:24:47.622-07:00Comments on The official Google Code blog: Gmail for Mobile HTML5 Series: Autogrowing TextareasMike Marchakhttp://www.blogger.com/profile/08067736591419106914noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-11300808.post-80228321063811553232010-03-24T20:18:04.928-07:002010-03-24T20:18:04.928-07:00How about shrinking as &quot;shrink to 1 line temp...How about shrinking as &quot;shrink to 1 line temporarily and then regrow as necessary&quot;, but performed as little as possible? One could, for example, count the number of newlines and only shrink if that count decreases.rauschmahttps://www.blogger.com/profile/05161748944927386101noreply@blogger.comtag:blogger.com,1999:blog-11300808.post-84181088516769968972009-09-16T09:53:31.462-07:002009-09-16T09:53:31.462-07:00Could you please explain to me what TEXTAREA_LINE_...Could you please explain to me what TEXTAREA_LINE_HEIGHT variable does? It does not seem to affect anything but number of lines to shift down. But how does it work?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-11300808.post-17930017723808759002009-07-25T12:08:23.209-07:002009-07-25T12:08:23.209-07:00Since pasting doesn&#39;t generate a key-up, you m...Since pasting doesn&#39;t generate a key-up, you might want to add grow() as a change handler, as well:<br /><br />&lt;textarea id=&quot;growingTextarea&quot;<br /> onkeyup=&quot;grow();&quot;<br /> onchange=&quot;grow();&quot;&gt;<br />&lt;/textarea&gt;Rod Knowltonhttps://www.blogger.com/profile/12914460319025626027noreply@blogger.comtag:blogger.com,1999:blog-11300808.post-13341851162223383632009-07-22T08:32:27.289-07:002009-07-22T08:32:27.289-07:00Works great for me! Here&#39;s how I wired it up t...Works great for me! Here&#39;s how I wired it up to all textareas on the page via jQuery:<br /><br />var TEXTAREA_LINE_HEIGHT = 13;<br /><br />function grow(textarea) {<br /> var newHeight = textarea.scrollHeight;<br /> var currentHeight = textarea.clientHeight;<br /> if (newHeight &gt; currentHeight) {<br /> textarea.style.height = newHeight + 5 * TEXTAREA_LINE_HEIGHT + &#39;px&#39;;<br /> }<br />}<br /><br />$(&#39;textarea&#39;).keyup(function(e){<br /> grow(e.srcElement);<br />});Gavinhttps://www.blogger.com/profile/11028746237547869136noreply@blogger.comtag:blogger.com,1999:blog-11300808.post-50140208927983930812009-07-22T00:41:56.975-07:002009-07-22T00:41:56.975-07:00Here is a solution I&#39;m using to grow and shrin...Here is a solution I&#39;m using to grow and shrink textarea when typing. It&#39;s little bit CSS and little bit Javascript.<br />The idea is to use container div wich will groove and shrink depending on it&#39;s content height. To do that I&#39;m using another div elemnt hidden under the textbox and seting textbox height to 100%. It works great on iPhone.<br /><br />Here is my solution with CSS and JS:<br /><br /><br />&lt;style&gt;<br />#growArea {<br /> width: 100%; height: 100%; position: absolute; top: 0px;<br />}<br /><br />#growArea, #textDiv {<br /> font-family: Arial; font-size: 12px; line-height: 15px;<br />}<br />#textDiv {<br /> position: relative; top: 0px; white-space: pre-wrap;<br />}<br />#textareaContainer {<br /> position: relative; width: 200px; min-height: 100px; padding-bottom: 75px;<br />}<br />&lt;/style&gt;<br />&lt;script&gt;<br />function resize() {<br /> document.getElementById(&#39;textDiv&#39;).innerHTML = document.getElementById(&#39;growArea&#39;).value;<br />}<br />&lt;/script&gt;<br />&lt;div id=&quot;textareaContainer&quot;&gt;&lt;div id=&quot;textDiv&quot;&gt;&lt;/div&gt;<br />&lt;textarea id=&quot;growArea&quot; onkeyup=&quot;resize();&quot;&gt;&lt;/textarea&gt;<br />&lt;/div&gt;coperminehttps://www.blogger.com/profile/11160109261571486631noreply@blogger.comtag:blogger.com,1999:blog-11300808.post-30554249501885918202009-07-21T11:58:59.495-07:002009-07-21T11:58:59.495-07:00There is a way of getting the height of the text w...There is a way of getting the height of the text when it is smaller than the textarea: setting the height of the textarea to 1 line temporary.<br /><br />The problem with this is that it requires updating the height of the area on every single key stroke. here is a Mootools version of the code. I have used a div container around the textarea to &quot;buffer&quot; the height changes, so the page layout does not get affected when the textarea height is set to one line:<br /><br />theTextarea.addEvent(&#39;keyup&#39;, function() {<br /> this.getParent().setStyle(&#39;height&#39;, this.clientHeight);<br /> if (this.scrollHeight &lt;= this.clientHeight) {<br /> this.setStyle(&#39;height&#39;, TEXTAREA_LINE_HEIGHT);<br /> }<br /> this.setStyle(&#39;height&#39;, this.scrollHeight + 5*TEXTAREA_LINE_HEIGHT);<br /> this.getParent().setStyle(&#39;height&#39;, this.clientHeight);<br />});Eneko Alonsohttps://www.blogger.com/profile/01609929152518624355noreply@blogger.com