cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <h1>
  <a href="https://dollarshaveclub.github.io/shave/" target="_blank">Shave</a>, A modern javascript plugin for truncating text within an html element.
</h1>
<h2>Time elapsed for <a href="https://dollarshaveclub.github.io/shave/" target="_blank">Shave</a> to truncate 50 elements: <span class="elapsed"></span></h2>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p><p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p><p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p><p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>
<p class="mh100">會全用民知多起功在有場館爾期臺多而不雄山選在場地市者電養說化運面遊聲時上教要下素的正一曾又如到性喜色體歷定部手里克業選陽響水起金園際吃權終麼意建本分香來象洋道方業動害有不財是了題此然把經會得善所建那各相標一來依正員由不古達解工面想推的</p>

            
          
!
            
              h1, 
h2,
p {
  margin: 1rem auto;
}
h1, 
h2 {
  max-width: 40rem;
  text-align: center;
}
p {
  max-width: 18.75rem;
  margin: 1rem auto;
}
            
          
!
            
              (function (global, factory) {
	typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
	typeof define === 'function' && define.amd ? define(factory) :
	(global.shave = factory());
}(this, (function () { 'use strict';

function shave(target, maxHeight) {
  var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

  if (!maxHeight) throw Error('maxHeight is required');
  var els = typeof target === 'string' ? document.querySelectorAll(target) : target;

  var character = opts.character || '…';
  var classname = opts.classname || 'js-shave';
  var spaces = opts.spaces || true;
  var charHtml = '<span class="js-shave-char">' + character + '</span>';

  if (!('length' in els)) els = [els];
  for (var i = 0; i < els.length; i += 1) {
    var el = els[i];
    var styles = el.style;
    var span = el.querySelector('.' + classname);
    var textProp = el.textContent === undefined ? 'innerText' : 'textContent';

    // If element text has already been shaved
    if (span) {
      // Remove the ellipsis to recapture the original text
      el.removeChild(el.querySelector('.js-shave-char'));
      el[textProp] = el[textProp]; // nuke span, recombine text
    }

    var fullText = el[textProp];
    var words = spaces ? fullText : fullText.split(' ');

    // If 0 or 1 words, we're done
    if (words.length < 2) continue;

    // Temporarily remove any CSS height for text height calculation
    var heightStyle = styles.height;
    styles.height = 'auto';
    var maxHeightStyle = styles.maxHeight;
    styles.maxHeight = 'none';

    // If already short enough, we're done
    if (el.offsetHeight <= maxHeight) {
      styles.height = heightStyle;
      styles.maxHeight = maxHeightStyle;
      continue;
    }

    // Binary search for number of words which can fit in allotted height
    var max = words.length - 1;
    var min = 0;
    var pivot = void 0;
    while (min < max) {
      pivot = min + max + 1 >> 1; // eslint-disable-line no-bitwise
      el[textProp] = spaces ? words.slice(0, pivot) : words.slice(0, pivot).join(' ');
      el.insertAdjacentHTML('beforeend', charHtml);
      if (el.offsetHeight > maxHeight) max = spaces ? pivot - 2 : pivot - 1;else min = pivot;
    }

    el[textProp] = spaces ? words.slice(0, max) : words.slice(0, max).join(' ');
    el.insertAdjacentHTML('beforeend', charHtml);
    var diff = spaces ? words.slice(max) : words.slice(max).join(' ');

    el.insertAdjacentHTML('beforeend', '<span class="' + classname + '" style="display:none;">' + diff + '</span>');

    styles.height = heightStyle;
    styles.maxHeight = maxHeightStyle;
  }
}

return shave;

})));

const startTime = new Date();

shave('p', 70, {spaces: false});

const endTime = new Date();
const elapsed = endTime - startTime;
$('.elapsed').html(`${elapsed} ms`);
console.log($('p').length);

            
          
!
999px
Loading ..................

Console