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);