Results 1 to 2 of 2
Jul 5, 2011, 01:43 #1
- Join Date
- Jul 2007
- 0 Post(s)
- 0 Thread(s)
textarea auto expand need help much! :(
I followed this article from Sitepoint
How to Build an Auto-Expanding Textarea jQuery Plugin, Part 2 » SitePoint
and everything is working fine until I added padding:3px to my textarea. In Google Chrome, now everything I type seems to auto expand the box no matter what is the height.
Can anyone shed some light? Thanks in advanced.I Dunno LOL ¯\(°_o)/¯
Jul 5, 2011, 04:48 #2
- Join Date
- Jan 2007
- Christchurch, New Zealand
- 101 Post(s)
- 4 Thread(s)
Have a look at these elementView properties
The scrollHeight includes the padding, so what you can do is to make use of one of the elementView properties, that being clientHeight, which gives you the height of the element including the padding.
Because both measurements include the padding, taking the difference between them removes the impact of the padding. The difference between scrollHeight and clientHeight If no change is required, will be 0. If the scrollHeight is 10 pixels larger than the clientHeight, then the box height needs to be 10 pixels larger.
How to achieve that? jQuery has a .height() method that gives you the actual height of the box, minus the padding.
So instead of using e.scrollHeight, you could replace it with this:
$(this).height() + e.scrollHeight - e.clientHeight
If height is 40, scrollHeight is 54 (46 + 8 padding) and clientHeight is 48 (40 + 8 padding), you would end up with:
40 + 54 - 48
which results in 40 + 6, which works out, since the scrollHeight is 6 larger than the clientHeight