captivationsoftware / react-sticky

<Sticky /> component for awesome React apps
MIT License
2.64k stars 385 forks source link

Adding a margin Top attribute #286

Closed ghost closed 5 years ago

ghost commented 5 years ago

marginTop (default: 0)

Sticky state will be triggered as usual only it will keap a margin from the top with the inputted value.

app.js

<StickyContainer>
  ...
  <Sticky marginTop={80}>
    { props => (...) }
  </Sticky>
  ...
</StickyContainer>

The above would result in an element that becomes sticky once its top is greater than or equal to 0px but it will scroll away from the top of the <StickyContainer /> by 80px.

vcarl commented 5 years ago

Hm how does this differ from topOffset?

ghost commented 5 years ago

the topOffset delays the event triggering by an offset of (x px) whereas the marginTop attributes don't delay the event triggering but keep the sticky object at an (x px) distance from the top. this is the behavior obtained by the topOffset attribute: oT and this is the behavior obtained by the marginTop attribute: Capture

Thanks for asking

vcarl commented 5 years ago

Hm when is this desirable behavior? This looks to me like it would make the content snap into place, jumping the size of the offset. Usually in my experience that's something to be avoided.

ghost commented 5 years ago

Well, this behavior is desired when you have a sticky navbar on top just like the shown example and no the changes were made to the code so it does not snap you can check out on this page as long -as it's online that is-

vcarl commented 5 years ago

I don't see any top margin on that page, and I see a number of scrolling bugs. I'm still not really sure what the intent here is, could you please add some code sandbox demos of what you can't accomplish? I'm going to close this but am happy to reopen if you can provide that information.

simjoeweb commented 5 years ago

Need this as well.