tag:blogger.com,1999:blog-11300808.post2823304741558926312..comments2024-03-27T04:19:57.377-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 "shrink to 1 line temp...How about shrinking as "shrink to 1 line temporarily and then regrow as necessary", 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?xyzhttps://www.blogger.com/profile/15451153704032513235noreply@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't generate a key-up, you m...Since pasting doesn't generate a key-up, you might want to add grow() as a change handler, as well:<br /><br /><textarea id="growingTextarea"<br /> onkeyup="grow();"<br /> onchange="grow();"><br /></textarea>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's how I wired it up t...Works great for me! Here'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 > currentHeight) {<br /> textarea.style.height = newHeight + 5 * TEXTAREA_LINE_HEIGHT + 'px';<br /> }<br />}<br /><br />$('textarea').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'm using to grow and shrin...Here is a solution I'm using to grow and shrink textarea when typing. It's little bit CSS and little bit Javascript.<br />The idea is to use container div wich will groove and shrink depending on it's content height. To do that I'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 /><style><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 /></style><br /><script><br />function resize() {<br /> document.getElementById('textDiv').innerHTML = document.getElementById('growArea').value;<br />}<br /></script><br /><div id="textareaContainer"><div id="textDiv"></div><br /><textarea id="growArea" onkeyup="resize();"></textarea><br /></div>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 "buffer" the height changes, so the page layout does not get affected when the textarea height is set to one line:<br /><br />theTextarea.addEvent('keyup', function() {<br /> this.getParent().setStyle('height', this.clientHeight);<br /> if (this.scrollHeight <= this.clientHeight) {<br /> this.setStyle('height', TEXTAREA_LINE_HEIGHT);<br /> }<br /> this.setStyle('height', this.scrollHeight + 5*TEXTAREA_LINE_HEIGHT);<br /> this.getParent().setStyle('height', this.clientHeight);<br />});Eneko Alonsohttps://www.blogger.com/profile/01609929152518624355noreply@blogger.com