Puff Out
The element swells into a big, soft blur and vanishes, like a puff of smoke blown away.
Reminder dismissedStand-up at 10:00
How to use it
- Paste the snippet just before
</head>. - Add
data-puff-outto any element.
Options
Add any of these attributes to the same element.
data-scale | The size it swells to. Default 2. |
data-blur | How blurred it ends, in px. Default 16. |
data-duration | How long it takes to leave. Default 700 ms. |
data-delay | How long it stays in view before it leaves. Default 1200 ms. |
data-loop | Fade back in, hold and puff out again. |
data-hold | How long it stays between exits, when looping. Default 1400 ms. |
It plays once it has been in view for data-delay, and ends hidden (visibility: hidden) but still taking up its space. To play it when you choose, such as when something is dismissed, leave the attribute off and call animacious.puffOut(el).
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/bundles/anime.umd.min.js"></script>
<script>
(function () {
// Puff Out: the element swells into a big, soft blur and vanishes, like a
// puff of smoke.
// Usage: <div data-puff-out>…</div>
// It plays once the element has been in view for data-delay ms, and ends
// hidden (visibility: hidden) but still taking up its space.
// Optional: data-scale (the size it swells to, default 2), data-blur (how
// blurred it ends, in px, default 16), data-duration (ms, default 700),
// data-delay (ms in view before it leaves, default 1200), data-loop (fade
// back in, hold and puff out again), data-hold (ms to stay between exits
// when looping, default 1400).
// Script use: animacious.puffOut(el, done) plays it on any element now,
// using its data-* options, and calls done afterwards.
var DEFAULTS = { scale: 2, blur: 16, duration: 700, delay: 1200, hold: 1400 };
function reduced() {
return window.matchMedia('(prefers-reduced-motion: reduce)').matches;
}
function leave(el, done) {
var d = el.dataset;
var t = +d.duration || DEFAULTS.duration;
var b = d.blur === undefined ? DEFAULTS.blur : +d.blur || 0;
if (reduced()) {
anime.utils.set(el, { opacity: 0 });
if (done) done();
return;
}
anime.utils.set(el, { filter: 'blur(0px)' });
anime.animate(el, {
scale: { to: +d.scale || DEFAULTS.scale, ease: 'out(2)' },
filter: { to: 'blur(' + b + 'px)', ease: 'out(1.5)' },
opacity: { to: 0, delay: t * 0.1, duration: t * 0.9, ease: 'inOut(1.5)' },
duration: t,
onComplete: function () {
if (done) done();
}
});
}
function cycle(el) {
var d = el.dataset;
var s = el._pfo;
leave(el, function () {
if (d.loop === undefined || d.loop === 'false') {
el.style.visibility = 'hidden';
return;
}
// Come back quietly in place, then go again once it's on screen.
setTimeout(function () {
anime.utils.set(el, { scale: 1, opacity: 0 });
el.style.filter = '';
anime.animate(el, {
opacity: 1,
duration: 400,
ease: 'out(2)',
onComplete: function () {
setTimeout(function () {
if (s.visible) cycle(el);
else s.waiting = true;
}, +d.hold || DEFAULTS.hold);
}
});
}, 400);
});
}
window.animacious = window.animacious || {};
window.animacious.puffOut = function (el, done) {
leave(el, function () {
el.style.visibility = 'hidden';
if (done) done(el);
});
};
function init() {
var io = new IntersectionObserver(function (entries) {
entries.forEach(function (e) {
var s = e.target._pfo;
s.visible = e.isIntersecting;
if (!e.isIntersecting) return;
if (!s.started) {
s.started = true;
var wait = e.target.dataset.delay;
setTimeout(function () { cycle(e.target); }, wait === undefined ? DEFAULTS.delay : +wait || 0);
} else if (s.waiting) {
s.waiting = false;
cycle(e.target);
}
});
}, { threshold: 0.2 });
document.querySelectorAll('[data-puff-out]').forEach(function (el) {
if (el._pfo) return;
el._pfo = {};
if (!reduced()) io.observe(el);
});
}
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init);
else init();
})();
</script><div class="card" data-puff-out>Reminder dismissed</div>
<!-- or a bigger, smokier puff: -->
<div class="card" data-puff-out data-scale="3" data-blur="24">Reminder dismissed</div>