Guest User

Untitled

a guest
Jan 21st, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. <script type="text/javascript">
  2.  
  3. var resizeTextarea = function() {
  4. this.style.height = "";
  5. if(this.scrollHeight > 12)
  6. {
  7. var
  8. $this = $(this),
  9. outerHeight = $this.outerHeight(),
  10. scrollHeight = this.scrollHeight,
  11. innerHeight = $this.innerHeight(),
  12. magic = outerHeight - innerHeight;
  13. this.style.height = scrollHeight + magic + "px";
  14.  
  15. }
  16. };
  17. // keydown is too soon and keyup only happens AFTER the character is inserted,
  18. // so the screen would have updated already.
  19. // So just set overflow: hidden on the textarea.
  20. // not sure about cut/paste events.
  21.  
  22. $(document).ready(function() {
  23. $('.autoresize').keydown(resizeTextarea);
  24. $('.autoresize').keyup(resizeTextarea);
  25. $('.autoresize').change(resizeTextarea);
  26. e = jQuery.Event("keydown");
  27. e.which = "";
  28. $(".autoresize").trigger(e);
  29. });
  30.  
  31. </script>
Add Comment
Please, Sign In to add comment