Last active
November 28, 2017 15:47
-
-
Save hexium310/b5080db30b45c8a1ba495e069435878a to your computer and use it in GitHub Desktop.
textareaの高さを自動で変えるクソコード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<textarea id="t"></textarea> | |
<style> | |
#t { | |
height: calc(1em + 2px); | |
font-size: 1em; | |
outline: none; | |
resize: none; | |
} | |
</style> | |
<script> | |
const t = window.t | |
t.addEventListener('input', function () { | |
const padding = parseInt(getComputedStyle(t).paddingTop) + parseInt(getComputedStyle(t).paddingBottom) | |
t.style.height = 'calc(1em + 2px)' | |
t.style.height = t.scrollHeight - padding + 'px' | |
}) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment