Skip to content

splitLines() is a jQuery plugin that takes a block of text and splits it up into separate lines based on the width of the box or a width passed to the function.

Notifications You must be signed in to change notification settings

jeremyharris/split_lines

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SplitLines jQuery Plugin

SplitLines ($.splitLines()) is a jQuery plugin that splits new lines of wrapped text into their own HTML elements, allowing you to animate or operate on each line individually. Works with nested HTML tags.

Requirements

  • jQuery 1.4.2 or later

Usage

HTML

<div id="mytext">
    This is an <strong>example</strong> of some long text 
    that we want to split into lines.
</div>

Javascript

$('#mytext').splitLines({
    tag: '<div><span class="someClass">',
    width: 200,
    keepHtml: true
});

Result

<div id="mytext">
    <div style="--line-index:0;"><span class="someClass">This is an</span></div>
    <div style="--line-index:1;"><span class="someClass"><strong>example</strong> of</span></div>
    <div style="--line-index:2;"><span class="someClass">some long</span></div>
    <div style="--line-index:3;"><span class="someClass">text that we</span></div>
    <div style="--line-index:4;"><span class="someClass">want to split</span></div>
    <div style="--line-index:5;"><span class="someClass">into lines.</span></div>
</div>

Now go forth, and animate!

For more demos, take a look at the demos.html file in this repo. There are some animated use cases in there as well.

License

Copyright (c) 2012 Jeremy Harris

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

splitLines() is a jQuery plugin that takes a block of text and splits it up into separate lines based on the width of the box or a width passed to the function.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •