From 4c3153d12bdc6af59f187babe3779b65b7f912e6 Mon Sep 17 00:00:00 2001 From: home Date: Fri, 14 Feb 2020 20:14:24 +0100 Subject: [PATCH] . --- form.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/form.js b/form.js index ea41527..1ad7848 100644 --- a/form.js +++ b/form.js @@ -1,2 +1,12 @@ - -$('textarea').autoResize(); \ No newline at end of file +addAutoresize = function() { + document.querySelectorAll('[data-autoresize]').forEach(function(element) { + element.style.boxSizing = 'border-box'; + var offset = element.offsetHeight - element.clientHeight; + document.addEventListener('input', function(event) { + event.target.style.height = 'auto'; + event.target.style.height = event.target.scrollHeight + offset + 'px'; + }); + element.removeAttribute('data-autoresize'); + }); +} +addAutoresize(); \ No newline at end of file