Package Exports
- truncated.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (truncated.js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Truncated.js
Truncated.js is a javascript plugin that shortens a text string based on a specified max-height & adds an ellipsis at the end.
Setup
npm install truncated.js --save-devbower install truncated.js --save-devRun
- Include truncated.js into your
vendorfile or in a<script>tag. - Add truncated
css/scssto yourcss. truncatethe element you'd like to give truncation to.
truncated('selector', maxHeight);🔥Basic Examples
Basic
truncated('selector', maxHeight);Or Multiples
truncated('selector', maxHeight);But not this one
truncated('selector:not([not this selector])', maxHeight);How?
Truncated.js trims a text string to a last full word of what can fit within a specified max height.
Why?
Truncated.js is made for a need for simpicity when it comes to text truncation. Several plugins that I've reviewed oversolve the issue for what people want when they want text truncation - for text to look nice in a specified space. Here's a basic example.
This plugin is small - ~1kb unminified & is meant to do 1 thing - truncate text based on a specified max height.
Options
If you'd like to not use the classname 'js-truncated', just use your own.
reframe('selector', 'classname');jQuery
There is jQuery version of Truncated.js which is even smaller (~76b) than plain Truncated.js unminified - so use it if you're already using jQuery.
$('selector').reframe(maxheight);&, if you'd like to use a custom classname instead of 'js-truncated'
$('selector').reframe(maxheight, 'classname');Issues
Truncation will produce results that are only questionably better. *Truncated.js does not measure line height + text height, store the original text value or count characters by desicion. If you'd like to do that, you could do that in a parent function before calling Truncation.js.