Skip to content
Advertisement

How to clamp/unclamp blocks of text in jQuery or Vanilla JS?

I can’t figure out how to do the following in jQuery or Vanilla JS.

For the layout below I want to do the following:

  1. Compress each text block using multi-clamp library to three (3) lines.
  2. When you click on the “Read more” button or on the block itself, that block of text should “expand” (unclamp) completely.

JavaScript
JavaScript
JavaScript

So far I’ve only figured out how to compress each block to three lines:

JavaScript

Advertisement

Answer

You can use the reload(options) method to achieve this.

reload(options)

You can change initial options when reloading through the options param, and use the original text to re-clamp when options.useOriginalText set to true. default: { …initOptions, useOriginalText: false }

Try this

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement