Performance: Scroll behavior control
Controls how the page scrolls and affects user interaction smoothness and visual stability during navigation.
window.scrollTo({ top: 0, behavior: 'smooth' });
window.scrollTo({ top: 0, behavior: 'auto' }); document.body.style.overflow = 'hidden'; setTimeout(() => { document.body.style.overflow = 'auto'; }, 500);
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Instant scroll with overflow toggle | Multiple style changes | 2 reflows | High paint cost due to layout shifts | [X] Bad |
| Native smooth scroll API | No extra DOM changes | 0 reflows | Low paint cost with smooth compositing | [OK] Good |
behavior: 'smooth' in window.scrollTo do in a Next.js app?behavior property controls how scrolling happens. Setting it to 'smooth' means the scroll moves gradually.window.scrollTo({ behavior: 'smooth' }) in Next.js makes the page scroll smoothly instead of jumping instantly.top and behavior keys: { top: 0, behavior: 'smooth' }.window.scrollTo with behavior: 'smooth', so scrolling is smooth to top.routeChangeComplete to ensure page is loaded, then scroll to element with smooth behavior.scrollIntoView({ behavior: 'smooth' }) scrolls smoothly to the element with id 'contact'.router.events.on('routeChangeComplete', () => { document.getElementById('contact').scrollIntoView({ behavior: 'smooth' }); }); [OK]Pass the test and this pattern moves unknown