Truncating Multi-line Text By Height – Shave.js

Category: Javascript , Recommended , Text | September 14, 2018
Author:dollarshaveclub
Views Total:2,343 views
Official Page:Go to website
Last Update:September 14, 2018
License:MIT

Preview:

Truncating Multi-line Text By Height – Shave.js

Description:

Shave.js is a lightweight, flexible JavaScript library used for truncating multiple lines of text to a height you specify. With or without custom ellipsis character.

How to use it:

Installation:

# Yarn
$ yarn add shave
# NPM
$ npm install shave --save

Place the core JavaScript file shave.js at the end of the document so the page loads faster.

<script src="dist/shave.js"></script>

Or import the shave as a module.

import shave from 'shave';

Call the shave function, specify the target text wrapping element and the max height for text truncating.

shave('p', 70);

Add a custom ellipsis to the end of the truncated text.

shave('selector', maxheight, {
   character: '......'
});

Changelog:

v2.5.0 (09/14/2018)

  • Update to the latest version

You Might Be Interested In:


Leave a Reply