Component location
Files are located in src/components/layout/showmore.
Inside you’ll find the component JS, an HTML example, and an SCSS file for styling.
Basic markup
Create a wrapper with data-anim-showmore, a content element with
data-anim-showmore-content, and a button with data-anim-showmore-button.
The button should start hidden using the hidden attribute and contain two
<span> labels: “Show more” and “Hide”.
<div data-anim-showmore class="block">
<div data-anim-showmore-content class="block__content"></div>
<button hidden data-anim-showmore-button type="button" class="block__more">
<span>Show more</span>
<span>Hide</span>
</button>
</div>
Put your text (or any content) inside the element marked with
data-anim-showmore-content.
Modes: height or items
Depending on what you’re collapsing, choose one of two modes via data-anim-showmore:
size— limit by content height (default)items— limit by number of list items
Limit by list items
For lists (ul/ol), set data-anim-showmore="items".
Then use data-anim-showmore-content on the list itself.
<div data-anim-showmore="items" class="block">
<ul data-anim-showmore-content class="block__content">
<li>Item #1</li>
<li>Item #2</li>
<li>Item #3</li>
<li>Item #4</li>
<li>Item #5</li>
</ul>
<button hidden data-anim-showmore-button type="button" class="block__more">
<span>Show more</span>
<span>Hide</span>
</button>
</div>
To set how many items are visible, provide a number in
data-anim-showmore-content (default: 3 in items mode).
<ul data-anim-showmore-content="4" class="block__content">
...
</ul>
Limit by height (text / content)
In the default (height) mode, you can set the maximum visible height in pixels
inside data-anim-showmore-content (default: 150).
Write only a number (no px).
<div data-anim-showmore class="block">
<div data-anim-showmore-content="200" class="block__content">
Lorem ipsum dolor sit amet consectetur, adipisicing elit...
</div>
<button hidden data-anim-showmore-button type="button" class="block__more">
<span>Show more</span>
<span>Hide</span>
</button>
</div>
When expanded, the wrapper receives the class --showmore-active.
The first span in the button is hidden and the second span is shown.
Click again to collapse back.
Control animation speed
To change the expand/collapse animation speed, set a number (milliseconds) on
data-anim-showmore-button. Default is 500.
<button hidden data-anim-showmore-button="1000" type="button" class="block__more">
<span>Show more</span>
<span>Hide</span>
</button>
Enable only on specific screen widths
To enable the feature only below/above a breakpoint, add
data-anim-showmore-media to the wrapper.
Pass a width and a type separated by comma:
max(default) — enable when viewport is smaller than the widthmin— enable when viewport is larger than the width
<div data-anim-showmore data-anim-showmore-media="768,min" class="block">
<div data-anim-showmore-content="200" class="block__content">...</div>
<button hidden data-anim-showmore-button="1000" type="button" class="block__more">
<span>Show more</span>
<span>Hide</span>
</button>
</div>
max) to keep long text compact.