Categories

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.0

    string   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.0

    string   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.
  • length

    version added: 1.0

    A number to set the length of chars for the scrunch result.

    Default: 50

  • ratio

    version added: 1.0

    A number between 0 (begin) and 1 (end) to set the position of scrunch and replace it with the spacer.

    Default: 1

  • cut

    version added: 1.0

    A boolean indicating whether to cut words.

    Default: true

  • spacer

    version added: 1.0

    A string to replace the text at the scrunch position.

    Default: '...'