Scroll to Section

Scrolling scenarios

  • Specific pages, often the homepage hav sections that we want to directly scroll to in the global nav

  • All pages have

Solutions;

  • Must handle direct navigation e.g. https://www.mysite.com/#contact

  • Must handle top-nav navigation from that page's nav bar

Ideally,

  • Should work perfectly on both staging and production, e.g. the origin does not need to be part of the URL

  • We do not want to have to handle in-page scrolling v. cross-page scrolling separately

  • CMS-link compatible

  • Keep the current state nav depending on the section you're on

Offset;

  • Support offsetting the scroll position for a fixed nav

  • Support sticky navs as well

  • Auto-calculate ( like Webflow does ) or allow a manual specification, stored on the body element

Options;

  • Hide the #hash

  • Delay re-scroll, used for lazy-load

  • Just remove lazy-load ( bandwidth impacts )

Usage Notes

  • Avoid using the scroll-to-section option in links

  • Instead, form your links as relative links

Specific page

e.g. /#contact

e.g. /about/#contact

ID's are case-sensitive

Current page

e.g. a section that you have on all pages, such as a Contact Us block that is part of your page footer.

e.g. #contact

Note the absence of the forward slash /, which is the homepage path. Here we avoid adding a path that since we want to stay on the current page.

Link from another site

e.g. https://www.mysite.com/#contact

This will also work, and smooth-scroll

Will these work in the CMS?

Technical Notes

Last updated

Was this helpful?