Performance: Carousel indicators
MEDIUM IMPACT
Carousel indicators affect the interaction responsiveness and visual stability during slide changes in a carousel component.
<script>const indicators = document.querySelector('.carousel-indicators'); indicators.addEventListener('click', e => { if(e.target.tagName === 'BUTTON'){ indicators.querySelector('.active')?.classList.remove('active'); e.target.classList.add('active'); } });</script>
<script>document.querySelectorAll('.carousel-indicators button').forEach(btn => btn.addEventListener('click', () => { document.querySelectorAll('.carousel-indicators button').forEach(b => b.classList.remove('active')); btn.classList.add('active'); }));</script>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Multiple event listeners on each indicator | Many event listeners, multiple class changes | N reflows per click | High paint cost due to frequent style changes | [X] Bad |
| Single event listener with event delegation | One event listener, two class changes per click | 1 reflow per click | Low paint cost, minimal style recalculations | [OK] Good |