Truncating Text Across DOM Nodes – shear.js

Category: Javascript , Recommended , Text | October 21, 2018
Author: zhengrenzhe
Views Total: 919
Official Page: Go to website
Last Update: October 21, 2018
License: MIT

Preview:

Truncating Text Across DOM Nodes – shear.js

Description:

shear.js is a powerful and standalone text truncation library that has the ability to truncate long block text by lines across DOM nodes. Based on the Selection Web API.

Installation:

# Yarn
$ yarn add shear.js

# NPM
$ npm install shear.js --save

Usage:

Import the shear.js.

import shear from 'shear.js';

The JavaScript to truncate your text by lines. Possible parameters:

  • element: container element
  • number: maximum number of lines
  • string: any strings displayed at the end of truncated text
// shear(element, number, string);
shear(document.getElementById('el'),  3, '<span>... (more)</span>');

Changelog:

10/21/2018

  • v2.1.1

You Might Be Interested In:


Leave a Reply