Created
December 11, 2013 02:55
-
-
Save cuing/7904461 to your computer and use it in GitHub Desktop.
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
#autoresize { | |
resize: none; | |
outline: none; | |
width: 300px; | |
word-break: break-all; | |
font-family:sans-serif; | |
font-size: 1em; | |
line-height: 1.2em; | |
margin: 0px; | |
} | |
#hiddenDiv { | |
width: 300px; | |
word-break: break-all; | |
line-height: 1.2em; | |
min-height: 1.2em; | |
font-family:sans-serif; | |
font-size: 1em; | |
display: none; | |
} | |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script> | |
<meta charset=utf-8 /> | |
<title>textarea auto height</title> | |
</head> | |
<body> | |
<textarea id="autoresize" rows="1"></textarea> | |
<div id="hiddenDiv"></div> | |
</body> | |
</html> |
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
var obj = $('#autoresize'); | |
var hidden = $('#hiddenDiv'); | |
function autoHeight() { | |
console.log(obj.value); | |
hidden.style.height = obj.offsetHeight; | |
} | |
obj.keyup(function() { | |
var txt = obj.val(); | |
hidden.text(txt); | |
obj.css('height', hidden.height()); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment