Parameters:
containerID - The ID of the div or span you want the text to fit into.
resizeID - The ID of the text element you want to resize
function resizeText(containerID, resizeID ) { var size = 16; var desired_width = $('#' + containerID).width(); $('#resizer').html($('#' + resizeID).html()); //setting resizer to desired text $('#resizer').css("font-size", size); var actual_width = $('#resizer').width(); //alert(desired_width + ' - ' + actual_width); while(desired_width <= actual_width+10) //+10 for saftey net { size--; $('#resizer').css("font-size", size); actual_width = $('#resizer').width(); } $('#' + resizeID).css("font-size", size); }
0 comments:
Post a Comment