Limit Long Text To X Lines – omitter.js

Category: Javascript , Text | August 30, 2018
Author: Tikubonn
Views Total: 594
Official Page: Go to website
Last Update: August 30, 2018
License: MIT

Preview:

Limit Long Text To X Lines – omitter.js

Description:

omitter.js is a fast JavaScript text truncation plugin to limit your long text to a specific number of lines using Element.innerText or TextNode.data.

How to use it:

Insert the stylesheet ‘omitter.css’ and JavaScript ‘omitter.js’ into the document.

<link href="omitter.css" rel="stylesheet"> 
<script src="omitter.js"></script>

Create a new Omitter object and specify the text container, number of lines and ellipsis character as follows:

var textContainer = document.querySelectorAll(".omitter-target");
var omitter = new Omitter(textContainer, 5, "..."); // limit to 5 lines.

Truncate the text.

omitter.omit();

Disable the omitter.

omitter.unomit();

Update the omitter.

omitter.update();

Toggle the omitter.

omitter.toggle();

You Might Be Interested In:


Leave a Reply