Last active
November 19, 2018 05:54
-
-
Save kcak11/4f992947bed0bed1194600f1876d9f60 to your computer and use it in GitHub Desktop.
Elastic TextArea
An Elastic TextArea component which resizes automatically based on the content entered in the textarea.
A Pen by K.C.Ashish Kumar on CodePen.
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 elastic placeholder="Add/Remove lines of text to auto-resize this textarea"></textarea> | |
<!-- | |
© 2018 https://kcak11.com / https://ashishkumarkc.com | |
--> |
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
/* | |
© 2018 https://kcak11.com / https://ashishkumarkc.com | |
*/ | |
(function() { | |
var doElastic = function(elem) { | |
elem.style.height = elem.getAttribute("default-height") + "px"; | |
elem.style.height = (elem.scrollHeight + 5) + "px"; | |
}; | |
[].forEach.call(document.querySelectorAll("textarea[elastic]"), function(et) { | |
et.setAttribute("rows", "1"); | |
et.style.resize = "none"; | |
et.style.overflow = "hidden"; | |
et.style.boxSizing = "border-box"; | |
et.setAttribute("default-height", et.offsetHeight); | |
doElastic(et); | |
et.addEventListener("input", function() { | |
doElastic(et); | |
}, false); | |
}); | |
}()); |
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
/* | |
© 2018 https://kcak11.com / https://ashishkumarkc.com | |
*/ | |
textarea { | |
font-family: Verdana; | |
border-top: none; | |
border-left: none; | |
border-right: none; | |
border-bottom: 2px solid #000; | |
background-color: #bcd9ed; | |
width: 50%; | |
outline: none; | |
font-size: 22px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment