I have a JSFiddle to take a look at here
I have been able to create an auto expanding and reduction textarea so as the user types it will auto expand and reduce if the user removes text. The problem is that the text bounces around and a scrollbar appears. I am not sure why the text is bouncing around as I type and I cant figure out how to remove the scrollbar.
When I remove
while($(this).outerHeight() > this.scrollHeight - parseFloat($(this).css("borderTopWidth")) - parseFloat($(this).css("borderBottomWidth"))) {
$(this).height($(this).height()-1);
};
Then the bouncing text goes away.
Also am I killing a dead horse with my JS code? Is there an easier way to do this? I feel like I am.
Also the first time you type in it the textarea inserts </body>
and </html>
into the textarea. This does not happen in my server, but is happening on JSFiddle only.
Any help to stop the bouncing text and remove scrollbars?
SOVLED:
I was finally able to solve my issue by changing the .keyup
to .keydown
in the function and removed the - parseFloat($(this).css("borderTopWidth")) - parseFloat($(this).css("borderBottomWidth"))
the bouncing text and scrollbar issues were fixed. Here is the code that is also on the JSFiddle example
.keydown(function(e) {
while($(this).outerHeight() < this.scrollHeight) {
$(this).height($(this).height()+1);
};
while($(this).outerHeight() > this.scrollHeight) {
$(this).height($(this).height()-1);
};
});