To enable smooth scrolling with section locking on click using horizontal scroll in Webflow, follow these steps to create a seamless navigation experience for a menu (like a pizza category slider).
#pizza
, #calzones
, etc.).These let the scroll lock to each section automatically when scrolling manually.
#pizza
#calzones
#salads
Webflow doesn’t natively support smooth horizontal scroll with anchor links, so we add custom code next.
tag and add this script:
<script> document.querySelectorAll('a[href^="#"]').forEach(link => { link.addEventListener('click', function(e) { e.preventDefault(); const target = document.querySelector(this.getAttribute('href')); if (target) { target.scrollIntoView({ behavior: 'smooth', inline: 'start', block: 'nearest' }); } }); });</script>
Create a horizontal scroll layout with category sections using flex layout, apply scroll snapping, and link each category using IDs. Then, add JS to support smooth scrolling to horizontal sections on click. This creates a clean, locked scrolling experience for your pizza shop’s menu in Webflow.