jQuery.shrink()
Categories: Utilities
jQuery.shrink( string, [ length ] )Returns: String
Plugin: jQuery.string
Description: Shrink a text to a speciefied length.
-
jQuery.shrink( string, [ length ] )
version added: 1.0string A string to shrink.
length A number to set the length of chars for the shrinked result. Default is 50.
-
jQuery.shrink( string, [ options ] )
version added: 1.0string A string to shrink.
length A set of key/value pairs that configure the scrunch.
The jQuery.shrink()
method shrink the length of a text in different modes.
With the ratio argument you can set the shrink position, so you can trim the begin, end or middle of a text. The shrinked text will replaced with a specified spacer.
-
Shrink a text at the end.
Code:
jQuery.shrink("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor.")
Results:
Lorem ipsum dolor sit amet, consetetur sad...
-
Shrink a text at the begin.
Code:
jQuery.shrink( "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor.", { ratio: 0 });
Results:
...scing elitr, sed diam nonumy eirmod tempor.
-
Shrink a text at the middle to length 50 without cut a word.
Code:
jQuery.shrink( "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor.", { ratio: 0, cut: false, spacer: "....." });
Results:
Lorem ipsum dolor sit.....nonumy eirmod tempor.