Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type="text/javascript">
- var resizeTextarea = function() {
- this.style.height = "";
- if(this.scrollHeight > 12)
- {
- var
- $this = $(this),
- outerHeight = $this.outerHeight(),
- scrollHeight = this.scrollHeight,
- innerHeight = $this.innerHeight(),
- magic = outerHeight - innerHeight;
- this.style.height = scrollHeight + magic + "px";
- }
- };
- // keydown is too soon and keyup only happens AFTER the character is inserted,
- // so the screen would have updated already.
- // So just set overflow: hidden on the textarea.
- // not sure about cut/paste events.
- $(document).ready(function() {
- $('.autoresize').keydown(resizeTextarea);
- $('.autoresize').keyup(resizeTextarea);
- $('.autoresize').change(resizeTextarea);
- e = jQuery.Event("keydown");
- e.which = "";
- $(".autoresize").trigger(e);
- });
- </script>
Add Comment
Please, Sign In to add comment