Performance: Scroll-snap containers
MEDIUM IMPACT
Scroll-snap containers affect the smoothness and responsiveness of scrolling interactions on a page.
<div class="overflow-x-scroll snap-x proximity"> <img class="inline-block w-64 h-40 snap-center" src="img1.jpg" /> <img class="inline-block w-64 h-40 snap-center" src="img2.jpg" /> <img class="inline-block w-64 h-40 snap-center" src="img3.jpg" /> </div>
<div class="overflow-x-scroll snap-x mandatory"> <img class="inline-block w-64 h-40 snap-start" src="img1.jpg" /> <img class="inline-block w-64 h-40 snap-start" src="img2.jpg" /> <img class="inline-block w-64 h-40 snap-start" src="img3.jpg" /> </div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Mandatory snap on many children | High (many snap points) | Multiple reflows on scroll | Medium | [X] Bad |
| Proximity snap with fewer snap points | Low | Single reflow or none on scroll | Low | [OK] Good |