js插件Autosize实现textarea标签高度自适应,且取消右边滚动条

2021-01-2609:26:51WEB前端开发Comments1,667 views字数 1512阅读模式

Autosize插件官方:https://github.com/jackmoore/autosize
案例代码:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/20882.html

<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'/>
<title>Simple Autosize for textareas</title>
<style>
    textarea {
        padding: 10px;
        vertical-align: top;
        width: 200px;
        resize:none;
        outline:none;
    }
    textarea:focus {
        outline-style: solid;
        outline-width: 2px;
    }
</style>
</head>
<body>
    <h3>max-height 300px</h3>
    <textarea style='max-height: 300px'>The coconut palm (also, cocoanut), Cocos nucifera, is a member of the family Arecaceae (palm family). It is the only accepted species in the genus Cocos.[2] The term coconut can refer to the entire coconut palm, the seed, or the fruit, which, botanically, is a drupe, not a nut. The spelling cocoanut is an archaic form of the word.[3] The term is derived from 16th-century Portuguese and Spanish coco, meaning "head" or "skull",[4] from the three small holes on the coconut shell that resemble human facial features.</textarea>

    <h3>no max-height</h3>
    <textarea>The coconut palm (also, cocoanut), Cocos nucifera, is a member of the family Arecaceae (palm family). It is the only accepted species in the genus Cocos.[2] The term coconut can refer to the entire coconut palm, the seed, or the fruit, which, botanically, is a drupe, not a nut. The spelling cocoanut is an archaic form of the word.[3] The term is derived from 16th-century Portuguese and Spanish coco, meaning "head" or "skull",[4] from the three small holes on the coconut shell that resemble human facial features.</textarea>
</body>
<script src='/autosize.min.js'></script>
<script>
    autosize(document.querySelectorAll('textarea'));
</script>
</html>

Autosize下载:autosize.zip 最好去下载官方最新的版本。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/20882.html

注意,以上案例代码中,还用css3样式去掉textarea标签的右下角拖动元素修改尺寸大小属性(resize:none)和轮廓线(outline:none)。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/gcs/20882.html

  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/gcs/20882.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定