正常来说 textarea 的高度是定死的,输入内容超出高度时只会产生内部滚动条,项目需求 要随内容增高而增高,
示例代码
<textarea class="input-area" autofocus maxlength="5000" placeholder="请输入内容">textarea>
const textarea = document.querySelector(".input-area");
textarea.focus()
textarea.addEventListener("input", function (e) {
this.style.height = "inherit";
this.style.height = `${this.scrollHeight}px`;
});
.input-area {
width: 100%;
border-radius: 0.08rem;
border: 0.02rem solid #E8E9EC;
resize: none;
max-height: 90%;
min-height: 2.24rem;
padding: 0.32rem;
overflow: auto;
word-break: break-all;
}