Skip to content

Sticky sections on scroll #1519

Answered by zahnster
jaymehta-twilio asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @jaymehta1986,

You can use the CSS sticky position ('position: sticky') to accomplish this.

You'll need a few things:

  • position="sticky" on the element you want to stick to the viewport when scrolled
  • top="someSpacingVar" on the same element (this sets how top from the viewport it should display, and you'll need to declare an actual spacing token there)

I have a simple codebox example set up for you to check out here:
https://codesandbox.io/s/hopeful-bird-v9dqm?file=/src/index.tsx

In my example, the sidebar is the sticky element. You will have to make the viewport small enough to trigger scrolling to see the effect.

Let me know if you need additional info!

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jaymehta-twilio
Comment options

Answer selected by zahnster
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants