This time I will share jQuery Plugin and tutorial about Truncate Text To Fit Its Container’s Height – LC Text Shortener, hope it will help you in programming stack.
Just another jQuery text truncation plugin for shortening text based on its container’s height or a fixed height value.
See Also:
How to use it:
1. Load the LC Text Shortener plugin’s files after jQuery library and we’re ready to go.
1 |
< script src = "/path/to/cdn/jquery.slim.min.js" ></ script > |
2 |
< script src = "/path/to/lc_text_shortener.min.js" ></ script > |
2. Call the function on the container whose text will be dynamically truncated based on its height.
1 |
< section id = "shortened_txt" > |
2 |
$( '#shortened_txt' ).lc_txt_shortener(); |
3. Specify the character(s) displayed at the end of the text after it has been truncated.
2 |
$( '#shortened_txt' ).lc_txt_shortener( '[..]' ); |
4. Truncate the text to a specific height instead (300px in this example).
2 |
$( '#shortened_txt' ).lc_txt_shortener( '[..]' , 300); |
5. Determine which HTML tags have to be maintained during shortening.
2 |
$( '#shortened_txt' ).lc_txt_shortener( '[..]' , 300, 'strong, a , em' ); |