Puff In
The element condenses out of a big, soft blur, shrinking and sharpening into place, like a puff of smoke played backwards.
Magic link sentCheck your inbox
How to use it
- Paste the snippet just before
</head>. - Add
data-puff-into any element.
Options
Add any of these attributes to the same element.
data-scale | The size it starts at. Default 2. |
data-blur | How blurred it starts, in px. Default 16. |
data-duration | How long it takes to condense. Default 800 ms. |
data-delay | Wait before the first entrance. Default 0 ms. |
data-loop | Hold, fade away and puff in again. |
data-hold | How long it stays before fading, when looping. Default 1400 ms. |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/bundles/anime.umd.min.js"></script>
<script>
(function () {
// Puff In: the element condenses out of a big, soft blur, shrinking and
// sharpening into place like a puff of smoke played backwards.
// Usage: <div data-puff-in>…</div>
// Optional: data-scale (the size it starts at, default 2), data-blur (how
// blurred it starts, in px, default 16), data-duration (ms, default 800),
// data-delay (ms before the first entrance), data-loop (hold, fade away
// and puff in again), data-hold (ms to stay when looping, default 1400).
var DEFAULTS = { scale: 2, blur: 16, duration: 800, delay: 0, hold: 1400 };
function reduced() {
return window.matchMedia('(prefers-reduced-motion: reduce)').matches;
}
function enter(el, done) {
var d = el.dataset;
var t = +d.duration || DEFAULTS.duration;
var b = d.blur === undefined ? DEFAULTS.blur : +d.blur || 0;
anime.utils.set(el, { scale: +d.scale || DEFAULTS.scale, opacity: 0, filter: 'blur(' + b + 'px)' });
anime.animate(el, {
scale: { to: 1, ease: 'out(3)' },
filter: { to: 'blur(0px)', ease: 'out(2)' },
opacity: { to: 1, duration: t * 0.7, ease: 'out(2)' },
duration: t,
onComplete: function () {
el.style.filter = ''; // drop the finished filter so text stays crisp
done();
}
});
}
function cycle(el) {
var d = el.dataset;
var s = el._pfi;
enter(el, function () {
if (d.loop === undefined || d.loop === 'false') return;
setTimeout(function () {
anime.animate(el, {
opacity: 0,
duration: 400,
ease: 'out(2)',
onComplete: function () {
// Wait until it's back on screen before the next entrance.
setTimeout(function () {
if (s.visible) cycle(el);
else s.waiting = true;
}, 500);
}
});
}, +d.hold || DEFAULTS.hold);
});
}
function init() {
var io = new IntersectionObserver(function (entries) {
entries.forEach(function (e) {
var s = e.target._pfi;
s.visible = e.isIntersecting;
if (!e.isIntersecting) return;
if (!s.started) {
s.started = true;
setTimeout(function () { cycle(e.target); }, +e.target.dataset.delay || DEFAULTS.delay);
} else if (s.waiting) {
s.waiting = false;
cycle(e.target);
}
});
}, { threshold: 0.2 });
document.querySelectorAll('[data-puff-in]').forEach(function (el) {
if (el._pfi) return;
el._pfi = {};
if (reduced()) return;
anime.utils.set(el, { opacity: 0 });
io.observe(el);
});
}
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init);
else init();
})();
</script><div class="card" data-puff-in>Magic link sent</div>
<!-- or a bigger, smokier puff: -->
<div class="card" data-puff-in data-scale="3" data-blur="24">Magic link sent</div>