rviscomi / trunk8

jQuery Truncation Plugin -- THIS PROJECT IS NO LONGER MAINTAINED
MIT License
703 stars 95 forks source link

min-height bug #48

Open Riant opened 10 years ago

Riant commented 10 years ago

Thanks for your great work, But when I set a min-height for the element to make the less-text box same height as the trunk8 box, trunk8 will get the min-height as line_height, there are some suggestions to fix that, wish it help you:

Change the line 342:

                $(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': floats, 'position': pos }).unwrap();

To:

                $(elem).html('<div id="' + wrapper_id + '">i</div>');

                /* 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': floats, 'position': pos });

And this will let we get the right line-height even when the box has padding-top/bottom.

But to make it works better, that change looks not enough, maybe we need to check the height in a temporary div-box when we cut the text one by one. So is that better to change from line 185 (I haven't test the code below.)

                this.html(bite);

                /* Check for overflow. */
                if (this.height() > line_height) {
                    upper = bite_size - 1;
                }

TO

                this.html('<div>'+ bite + '</div>');

                /* Check for overflow. */
                if (this.children('div').height() > line_height) {
                    upper = bite_size - 1;
                }

What's your opinion?