Hide Long Text Based On The Number Of Characters – Truncate.js

Category: Javascript , Text | April 10, 2018
Author: ashuparmarjain
Views Total: 1,177
Official Page: Go to website
Last Update: April 10, 2018
License: MIT

Preview:

Hide Long Text Based On The Number Of Characters – Truncate.js

Description:

Truncate.js is a small and easy-to-use JavaScript plugin used to hide your long text depending on the number of characters you specify.

How to use it:

Insert the main JavaScript file ‘truncate.js’ into the page.

<script src="truncate.js"></script>

Initialize the Truncate.js and specify the text container.

<p class="truncate-demo">
  Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eos alias commodi fuga vero, beatae quas iusto, at, reprehenderit ratione nisi consequatur sunt velit dolor deleniti hola repudiandae voluptatum sequi obcaecati quis.
</p>
Truncate({
  className:"truncate-demo"
});

By default, the Truncate.js library will truncate your text to 150 characters. You can specify the limit in the JavaScript as follow:

Truncate({
  className: "truncate-demo",
  char: "120"
});

Specify the string (typically Ellipsis) displayed at the end of the truncated text.

Truncate({
  className: "truncate-demo",
  truncateBy: "..."
});

Specify the number of times you want to show the truncate string.

Truncate({
  className: "truncate-demo",
  truncateBy: "...",
  numOfTruncateBy: 1
});

You Might Be Interested In:


Leave a Reply