3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

書き込むと自動的に拡大するTEXTAREA

3
Posted at

textareaは自動的に拡大してもらいましょう。

スクロールしながら長文を入力するのは嫌ですね。
下記のファイルを置いて、各htmlページに

```の1行を追加すると、すべてのtextareaが自動拡縮になります。

```javascript:auto_resize.js
document.addEventListener('DOMContentLoaded',function(event){
	autoResize_all();
},false);

function autoResize_all()
{
	nodes=document.getElementsByTagName('TEXTAREA');
	for(n=0;n<nodes.length;n++){
		autoResize(nodes[n]);
		nodes[n].addEventListener('input',function(event){autoResize(event);},false);
	}
}

function autoResize(event)
{
	node=event.target;
	if(node){
		if(node.scrollHeight < node.offsetHeight){
			node.style.height="initial";
		}
		if(node.scrollHeight > node.offsetHeight){
			node.style.height = node.scrollHeight + "px";
		}
	}
}
3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?