Closed zgood closed 11 years ago
I have update trunk8.js "getLineHeight" function to take in consideration floats and positions:
getLineHeight: function (elem) { var float = $(elem).css('float'); if (float !== 'none') { $(elem).css('float', 'none'); } var pos = $(elem).css('position'); if (pos === 'absolute') { $(elem).css('position', 'static'); }
var html = $(elem).html(),
wrapper_id = 'line-height-test',
line_height;
/* Set the content to a small single character and wrap. */
$(elem).html('i').wrap('<div id="' + wrapper_id + '" />');
/* Calculate the line height by measuring the wrapper.*/
line_height = $('#' + wrapper_id).innerHeight();
/* Remove the wrapper and reset the content. */
$(elem).html(html).css({ 'float': float, 'position': pos }).unwrap();
return line_height;
}
Thanks @zgood! Could you submit a pull request so I can test and merge?
This plugin does not work with floating or position elements, which makes it very limited in the senerios in which it can be used. Almost ALL of my dynamically created elements are floated or positioned, and those are the only elements I need to truncate text on. It's because the "getLineHeight" utility always comes back with "0" on those elements and then it just keeps truncating the string until there is nothing left. At least give an option to supply a line-height for those type of elements, because I know what the line-height I want.