Exit layout animation
Automatically animates elements leaving the layout, and optionally specifies their final properties and timings using the leaveTo state parameters (defaults to opacity: 0).
Exit layout animation code example
import { createLayout, utils } from 'animejs';
const [ $button ] = utils.$('.controls button');
const layout = createLayout('.layout-container', {
duration: 250,
ease: 'outQuad',
leaveTo: {
transform: 'translateY(-100px) scale(.25)',
opacity: 0,
duration: 350, // Applied to the elements leaving the layout
ease: 'out(3)' // Applied to the elements leaving the layout
}
});
function removeItem() {
layout.update(({ root }) => {
const items = root.querySelectorAll('.item:not(.is-hidden)');
if (!items.length) return $button.disabled = true;
items[0].classList.add('is-hidden'); // temporarily hide the element using `display: none`
}).then(() => {
// Remove the elements from the DOM when the animation finishes
layout.leaving.forEach($el => $el.remove());
});
}
$button.addEventListener('click', removeItem);
<div class="large layout centered row">
<div class="layout-container col grid-layout row">
<div class="item col">1</div>
<div class="item col">2</div>
<div class="item col">3</div>
<div class="item col">4</div>
<div class="item col">5</div>
<div class="item col">6</div>
<div class="item col">7</div>
<div class="item col">8</div>
<div class="item col">9</div>
<div class="item col">10</div>
</div>
</div>
<div class="medium row">
<fieldset class="controls">
<button class="button">Remove item</button>
</fieldset>
</div>
#layout-usage-exit-layout-animation .is-hidden {
display: none;
}