Created
October 25, 2019 09:42
-
-
Save hadaytullah/3ff98e47c1879b4626be42baddabd61e to your computer and use it in GitHub Desktop.
Auto extending HTML text area
This file contains hidden or 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
$('#ta').on('keydown',function(){ | |
var thisInput = event.target; | |
var $thisInput = $(thisInput); | |
var previousScrollHeight = $thisInput.data('previous-scroll-height'); | |
if(previousScrollHeight === null || previousScrollHeight === undefined){ //first time | |
$thisInput.data('previous-scroll-height',thisInput.scrollHeight); | |
previousScrollHeight = thisInput.scrollHeight; | |
} | |
if(previousScrollHeight !== thisInput.scrollHeight){ | |
$thisInput.css('height', 'auto' ); | |
$thisInput.height( thisInput.scrollHeight ); | |
$thisInput.data('previous-scroll-height', thisInput.scrollHeight); | |
} | |
}); |
This file contains hidden or 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
<div id='canvas'> | |
</div> | |
<textarea id='ta'></textarea> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment