Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 397343569a
Fetching contributors…

Cannot retrieve contributors at this time

59 lines (45 sloc) 2.613 kb

AutoResize v1.1.2

Tuesday, October 10th 2011

AutoResize is a jQuery Plugin that matches a textarea to the height of its text content. It is intended to be used with the latest version of jQuery: http://code.jquery.com/jquery-latest.js

Homepage: http://azoffdesign.com/autoresize

License

Copyright 2011, Jonathan Azoff

Dual licensed under the MIT or GPL Version 2 licenses.

http://jquery.org/license

Usage

jQuery(selector).autoResize();
  • selector The jQuery selector, targeting a <textarea> element to apply the auto resize to

Events

Apart from regular DOM events, an auto-resized textarea emits events to inform the listeners of its state. To listen to these events, simply listen for one of the following events on an overscrolled element:

  • autoresize:resize
    • Called after re-sizing happens. This event is only called when the size actually changes.

Here is an example using jQuery's bind() method, listening for resize:

$('selector').autoresize().bind('autoresize:resize', function(e, height){ console.log(this, 'is', height, 'px tall') });

Notes

AutoResize only works with textareas, so please don't complain if your contenteditable elements aren't resizing when you apply this plug-in to them. This plug-in was designed to solve what should be a very simple problem, but seemingly fell short of a complete solution in many past attempts. Each auto-resizing plug-in I've tested has failed in situations where the textarea is hidden, or messes with selector logic by inserting a cloned element of the same class. AutoResize attempts to be as unobtrusive as possible, while still maintaining resilience in the face of DHTML. Use it at your own risk and please submit bug reports on the Issue Tracker

Special Thanks

This plug-in would not exist if it was not for a specific need and level of quality demanded by a particular project. For AutoResize, that inspiration is RentJuice (http://rentjuice.com), which uses the plug-in in many of their new features. Special thanks to RentJuice and the entire dev team for allowing this plug-in to go open-sourced!

Change Log

  • 1.1.1
    • Fixed page jump behavior on autoscroll (issue)
  • 1.1.1
    • Fixed page jump behavior on autoscroll (issue)
  • 1.1.0
    • No more clones, long live scrollHeight!
  • 1.0.0
    • Out of the gate, hurrah!
Jump to Line
Something went wrong with that request. Please try again.