Scroll in
Things that slide or fade in the first time they scroll into view, for landing pages. Add data-momo-in to anything. Plus a thin reading progress bar for long articles.
Scroll in
These demos play again each time they come back into view (data-momo-in-repeat), so scroll them out and back, or press the button.
the default
150ms later
300ms later
from the side
from above
from the other side
<div class="grid sm:grid-cols-3 gap-4" id="in-demo">
<div class="box p-6 text-center" data-momo-in="up" data-momo-in-repeat><b>up</b><br><span class="text-muted text-sm">the default</span></div>
<div class="box p-6 text-center bg-yellow-soft" data-momo-in="zoom" data-momo-in-repeat data-momo-in-delay="150"><b>zoom</b><br><span class="text-muted text-sm">150ms later</span></div>
<div class="box p-6 text-center bg-violet-soft" data-momo-in="fade" data-momo-in-repeat data-momo-in-delay="300"><b>fade</b><br><span class="text-muted text-sm">300ms later</span></div>
<div class="box p-6 text-center" data-momo-in="start" data-momo-in-repeat><b>start</b><br><span class="text-muted text-sm">from the side</span></div>
<div class="box p-6 text-center bg-green-soft" data-momo-in="down" data-momo-in-repeat data-momo-in-delay="150"><b>down</b><br><span class="text-muted text-sm">from above</span></div>
<div class="box p-6 text-center" data-momo-in="end" data-momo-in-repeat data-momo-in-delay="300"><b>end</b><br><span class="text-muted text-sm">from the other side</span></div>
</div>
<button class="btn btn-sm mt-4" type="button" onclick="document.querySelectorAll('#in-demo [data-momo-in]').forEach(function(e){e.classList.remove('is-in');void e.offsetWidth;e.classList.add('is-in')})"><i class="mi mi-refresh-cw" aria-hidden="true"></i> Play again</button>One after another
data-momo-in-stagger on a list or grid brings its children in one by one, 80ms apart (or the number you give it).
Fast
One small file.
Phones
Folds to fit.
For everyone
Keys and screen readers.
<div class="features" data-momo-in-stagger="120" data-momo-in-repeat id="stagger-demo">
<div class="feature"><span class="feature-icon bg-yellow-soft"><i class="mi mi-bolt" aria-hidden="true"></i></span><h3>Fast</h3><p>One small file.</p></div>
<div class="feature"><span class="feature-icon bg-violet-soft"><i class="mi mi-smartphone" aria-hidden="true"></i></span><h3>Phones</h3><p>Folds to fit.</p></div>
<div class="feature"><span class="feature-icon bg-green-soft"><i class="mi mi-accessibility" aria-hidden="true"></i></span><h3>For everyone</h3><p>Keys and screen readers.</p></div>
</div>
<button class="btn btn-sm mt-4" type="button" onclick="var s=document.getElementById('stagger-demo');[...s.children].forEach(function(e){e.classList.remove('is-in')});void s.offsetWidth;[...s.children].forEach(function(e){e.classList.add('is-in')})"><i class="mi mi-refresh-cw" aria-hidden="true"></i> Play again</button>Options
| Attribute | Does |
|---|---|
data-momo-in | up (default), down, start, end, fade or zoom |
data-momo-in-stagger="80" | On a parent: its children come in one after another, this many milliseconds apart |
data-momo-in-delay="200" | Wait this many milliseconds first |
data-momo-in-speed | slow (1s) or fast (0.35s); the default is 0.6s |
data-momo-in-repeat | Play every time it comes into view, not only the first |
--in-distance | How far it travels (24px) |
Use it on a few headings and sections, not on everything: motion is there to guide the eye, and text that keeps moving is hard to read.
Reading progress
Put <div class="scroll-progress" aria-hidden="true"></div> anywhere in the page: a thin bar along the very top fills as the page is read. .scroll-progress-below puts it under a sticky navbar. This page has one: look at the top as you scroll.
| Class / setting | Does |
|---|---|
.scroll-progress | The bar, fixed along the top in the brand color |
.scroll-progress-below | Under a sticky or fixed navbar |
--scroll-progress-color / --scroll-progress-h | Its color and height (4px) |
Accessibility
- For readers who prefer less motion, everything is simply there: nothing slides.
- Without JavaScript, and when printing, everything is shown too. Nothing is ever hidden for good.
- The progress bar is decoration, so it has
aria-hidden="true".