JSFiddle - React, Tailwind, and code Playground
HTML
<h3>
wxwxwxwx
</h3>
<div ng-app="test">
<span ng-init="text = 'Lorem ipsum dolor'"></span>
<h3 data-ellipsis data-ng-bind="text">
Lorem ipsum dolor sit amet, consectetur adipisc Lorem ipsum dolor sit amet, consectetur adipisc Lorem ipsum dolor sit amet, consectetur adipisc Lorem ipsum dolor sit amet, consectetur adipisc
</h3>
</div>
CSS
h3 {
font-size: 18.73px;
line-height: 1.2em;
}
JavaScript
document.querySelector('h3').textContent = ''.concat(
'clientHeight: ',
document.querySelector('h3').clientHeight,
' scrollHeight: ',
document.querySelector('h3').scrollHeight
);
/**
* Angular directive to truncate multi-line text to visible height
*
* @param bind (angular bound value to append) REQUIRED
* @param ellipsisAppend (string) string to append at end of truncated text after ellipsis, can be HTML OPTIONAL
* @param ellipsisAppendClick (function) function to call if ellipsisAppend is clicked (ellipsisAppend must be clicked) OPTIONAL
* @param ellipsisSymbol (string) string to use as ellipsis, replaces default '...' OPTIONAL
* @param ellipsisSeparator (string) separator to split string, replaces default ' ' OPTIONAL
*
* @example <p data-ellipsis data-ng-bind="boundData"></p>
* @example <p data-ellipsis data-ng-bind="boundData" data-ellipsis-symbol="---"></p>
* @example <p data-ellipsis data-ng-bind="boundData" data-ellipsis-append="read more"></p>
* @example <p data-ellipsis data-ng-bind="boundData" data-ellipsis-append="read more" data-ellipsis-append-click="displayFull()"></p>
*
*/
angular.module('dibari.angular-ellipsis', [])
.directive('ellipsis', ['$timeout', '$window', '$sce', function($timeout, $window, $sce) {
var AsyncDigest = function(delay) {
var timeout = null;
var queue = [];
this.remove = function(fn) {
if (queue.indexOf(fn) !== -1) {
queue.splice(queue.indexOf(fn), 1);
if (queue.length === 0) {
$timeout.cancel(timeout);
timeout = null;
}
}
};
this.add = function(fn) {
if (queue.indexOf(fn) === -1) {
queue.push(fn);
}
if (!timeout) {
timeout = $timeout(function() {
var copy = queue.slice();
timeout = null;
// reset scheduled array first in case one of the functions throws an error
queue.length = 0;
copy.forEach(function(fn) {
fn();
});
}, delay);
}
};
};
var asyncDigestImmediate = new AsyncDigest(0);
var...