In my current task, it was necessary to arrange the text in width with the alignment of the last line in the center. The solution could be the CSS property text-align-last, but it is supported only in Internet Explorer. The search for similar jQuery plugins did not return any results, so I wrote my own.
I put the finished plugin
hereUsage example
$(selector).lastLine({ 'display':'block', 'text-align':'center' });
As you can see from the example, the CSS for the last line is passed as a parameter.
')
Additional options
endLineTag - The tag name for the strut. The default is "div."
endLineClass - The class name for the spacer. The default is “endLine”.
lastLineTag - The tag name for the last line. The default is "span".
lastLineClass - The class name for the last line. The default is "spanLastLine".
anchorPrefix - Class prefix for anchor, in case of conflicts. The default is an. The class name is always random. Prefix + random number from 0 to 100000.
Example
We need to wrap the last line of all paragraphs in a DIV with the LastLineOfP class:
$("p").lastLine({},{ 'lastLineClass':'LastLineOfP', 'lastLineTag':'div' });
UPDATEHaving made the work on the bugs added the following to the plugin:
- The search for the last line comes by adding an anchor from the end of the text, and not by enumerating words. Thank you, egorinsk
- The approximate width of the column is being determined. Need to put the right strut. (Need optimization)
- If the last line indicates the alignment in width, then it will be so. Thanks to Dmitry_f for an example.
- If the end of the line is inside another object, for example in a span, then this object is closed.
- The syntax for using the plugin has changed, settings have appeared.