I'm using Material UI's <Appbar />
component, and this compiles to a div with position: fixed;. The "scroll to hide" effect here uses visibility: hidden;
and transform: translateY(-59px);
to hide the bar.
Now, I would like to add a sticky div under this <Appbar />
component, but what happens is that the sticky div is not affected by the <Appbar />
in the DOM flow. So, essentially, it just scrolls up to the top (under or over the <Appbar />
, depending on the z-index), and then sticks, like it should.
I understand that position: fixed;
removes the elements natural space in the document and makes it "floating", so I guess this is the reason the sticky div does not respond to it.
What I would like is that the sticky div keeps it place under the <Appbar />
, and when the <Appbar />
disappears the sticky div shifts its position in the document accordingly. Anyone who can give me a tip here?
See a sandbox here: https://codesandbox.io/s/quiet-fast-pb9fv?file=/src/HideAppBar.js