<div class="artitle">
<textarea autoHeight="true">text</textarea>
</div>
<!-- 控制文本域高低的js -->
<script>
$.fn.autoHeight = function(){
function autoHeight(elem){
elem.style.height = 'auto';
elem.scrollTop = 0; //防抖动
elem.style.height = elem.scrollHeight + 'px';
}
this.each(function(){
autoHeight(this);
$(this).on('keyup', function(){
autoHeight(this);
});
});
}
$('textarea[autoHeight]').autoHeight();
</script>
文本域的css样式:
textarea {width:93%; min-height:60px; overflow:hidden;}
.artitle{
line-height: 2em;
letter-spacing: 2px;
word-spacing: 0.5em;
text-indent: 2em;
font-size: 1.3em;
font-family: 微软雅黑;
padding: 10px 0px;
margin: 0px;
width: 100%;
}
文本域随着字数增加,高度自动增加
最新推荐文章于 2022-08-25 10:03:13 发布