Serhii Zavatyi’s Post

View profile for Serhii Zavatyi

I build Webflow sites for founders and marketing teams | Official Webflow Partner

Quick tech tip of the day (Webflow edition). If you have a blog article page with a ToC block on it that has internal scrolling, and you want to make it automatic with your page content scroll - here’s a quick JavaScript solution: // Script START <script> document.addEventListener('DOMContentLoaded', function () {  const toc = document.querySelector('.blog_toc-inner');  if (!toc) return;  const observer = new MutationObserver(() => {   const activeLink = toc.querySelector('.w--current');   if (activeLink) {    toc.scrollTo({     top: activeLink.offsetTop - toc.clientHeight / 2 + activeLink.clientHeight / 2,     behavior: 'smooth'    });   }  });  observer.observe(toc, {   subtree: true,   attributeFilter: ['class'],   attributes: true  }); }); </script> // Script END Works perfectly with Finsweet library, and even Locomotive scroll by LENIS. Enjoy! ✌ #DevTips #Webflow #JavaScript #CodeSolution #WebDevelopment

  • graphical user interface, text, application

To view or add a comment, sign in

Explore content categories