Layout · 09 of 23
Stagger Load
Sequential item entry
<button class="trigger-btn" id="staggerBtn">Reload List</button>
<ul class="stagger-list-ui" id="staggerList">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
.trigger-btn {
padding: 0.6rem 1.2rem;
background: #7c5cff;
color: white;
border: none;
border-radius: 6px;
font-weight: 600;
cursor: pointer;
}
.stagger-list-ui {
list-style: none;
padding: 0;
width: 100%;
max-width: 320px;
}
.stagger-list-ui li {
background: #333;
color: #f0f0f5;
padding: 0.5rem;
margin-bottom: 0.5rem;
border-radius: 4px;
opacity: 0;
transform: translateX(-20px);
}
@keyframes staggerFade {
to { opacity: 1; transform: translateX(0); }
}
var staggerBtn = document.getElementById('staggerBtn');
var staggerList = document.getElementById('staggerList');
var items = staggerList.querySelectorAll('li');
var STEP = 0.1; // s delay between items
var EASE = 'cubic-bezier(0.16, 1, 0.3, 1)';
function play() {
// Clear any running animation, force a reflow so it can restart
items.forEach(function (li) { li.style.animation = 'none'; });
void staggerList.offsetWidth;
items.forEach(function (li, i) {
li.style.animation =
'staggerFade 0.5s ' + EASE + ' forwards ' + (i * STEP) + 's';
});
}
staggerBtn.addEventListener('click', play);
play(); // animate on load too