Skip to content

Instantly share code, notes, and snippets.

@hexium310
Last active November 28, 2017 15:47
Show Gist options
  • Save hexium310/b5080db30b45c8a1ba495e069435878a to your computer and use it in GitHub Desktop.
Save hexium310/b5080db30b45c8a1ba495e069435878a to your computer and use it in GitHub Desktop.
textareaの高さを自動で変えるクソコード
<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