Here's what I came up with in jQuery:
$('#workdescription').keyup(function(e){
var key = (e.keyCode ? e.keyCode : e.which);
var ln = $(this).val().length;
var growAt = 47;
var normal = false; //a 'normal' key (a-z)
if((key > 106 && key < 113) || (key > 83 && key < 93) || (key > 60 && key < 71))
normal = true;
if(ln % growAt == 0 || normal == false){
ln = Math.floor(ln / growAt);
var h = 24;
if(ln != 0)
h += 20 * ln;
if($(this).css('height') == h + 'px')
return;
h = h + 'px';
$(this).animate({height: h}, 200,\"swing\", function(){});
}
});
It worked pretty well, but lagged the browser a lot. Turns out someone beat me to the punch: http://www.unwrongest.com/projects/elastic/.
The plugin referenced at the link above is really pretty cool, and uses a hidden div to calculate height rather than the static-int sizes I was using. Check it out!
0 comments:
Post a Comment