Is there anyway through CSS or Javascript set the height of the textarea based on the content? I have a hardcoded height in my CSS but i wanted it to default so there is no vertical scroll bar on page load?
相关问题
- Views base64 encoded blob in HTML with PHP
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
This other question about WhatsApp like input has been incorrectly marked as a duplicate of this current question. As I cannot answer there, I'm answering it here.
I was trying to create a WhatsApp like input area, with the following features:
Here is my pure CSS solution, if anyone is looking for it (like I was a few minutes ago).
This work for me
How about http://www.jacklmoore.com/autosize/ Drop Autosize into any web page and it should Just Work. The source is short and well commented if you are curious to how it works.
Source: https://github.com/jackmoore/autosize
Demo: http://www.jacklmoore.com/autosize/
Without plugins you could do something like
Resizing the textarea while it does have a scrollbar (so elem.clientHeight < elem.scrollHeight). You can do it quite easily even without JQuery, in plain javascript.
Didn't test the code, it's just the "concept".
EDIT: Dumb me, it's much easier, no loops...
Hey can go with ExpandingTextArea plugin in which an invisible clone pre element is maintained behind your textarea. Whenever the height of this pre changes, the textarea is updated.
It is simple just include "expanding.js" and "jQuery" in your page and add class "expanding" to the textarea to which u need to expand.
Follow the link for more details and Demo
Note: It will work on document load for already added texts
You can use the auto resize plugin using the jQuery UI Autoresize
Here is the html,
and here is the jquery,
see DEMO