テキストエリア内で折り返しされた時にheightを自動で変更したくて書きました。
デモ
コード.gs
function doGet() {
return HtmlService.createHtmlOutputFromFile("index");
}
|
意訳この機能がやること 指定したHTMLファイルを表示する |
index.html
<!DOCTYPE html>
<html>
<body>
<textarea id="ta"></textarea>
<script>
var ta = document.getElementById("ta");
ta.oninput = taInput;
function taInput(e){
ta.style.height = "1em";
if(ta.scrollHeight > ta.offsetHeight){
ta.style.height = ta.scrollHeight + "px";
}
}
</script>
</body>
</html>
|
参考
element.clientHeight
https://developer.mozilla.org/ja/docs/Web/API/Element/clientHeight
Element.scrollHeight
https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight
HTMLElement.offsetHeight
https://developer.mozilla.org/ja/docs/Web/API/HTMLElement/offsetHeight
element.clientHeight
https://developer.mozilla.org/ja/docs/Web/API/Element/clientHeight
Element.scrollHeight
https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight
HTMLElement.offsetHeight
https://developer.mozilla.org/ja/docs/Web/API/HTMLElement/offsetHeight






















