[Help] How to use sticky for each segment #1482
-
Help WantedI've few section(category), each section I want to have an divider info(category) sticky on top when the user scroll down. How to achieve this? Question:
If you have any divider sticky example or something that doing what I need, please let me know. Thanks. Testcase |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
@YauKeng The sticky module sets the height depends on the content within the sticky element. Your sticky element is only 14px high. So, it's correct.
As far as I tested in your fiddle, it works as it supposed to be. The category 2 sticky disappears as soon as it's context ( And when I scroll back to the top of the page, the sticky element of category 1 is still appearing as expected. I'm not sure which sticky info you're expecting to see when you scroll back to top. Maybe, this is not the problem you're talking about or I couldn't catch your explanation about your issue very well. A screenshot or animation GIF may be helpful to clarify better. |
Beta Was this translation helpful? Give feedback.
-
@ko2in can you try with smaller window? As you can see from my image and gif, I've 3 issue.
|
Beta Was this translation helpful? Give feedback.
-
@YauKeng OK. Now I can reproduce it with smaller screen. This issue causes because negative margin set on the cards container: So, with very small height of your sticky container with 14px is totally covered by the cards container. The cards container need to have negative margin to cover the space taken by the card elements inside. So, I guess you should wrap your cards within another container and add the top margin or padding. And your sticky elements also have spaces such as margin, and padding around the box. So, the calculation of the sticky position is slightly incorrect due to these unexpected spaces in your use-case. I think you should adjust the HTML, CSS and customize to suit your need. Here's fiddle that would give you the result you expected. https://jsfiddle.net/a2srh5gv/1/ |
Beta Was this translation helpful? Give feedback.
-
Thanks @ko2in |
Beta Was this translation helpful? Give feedback.
@YauKeng OK. Now I can reproduce it with smaller screen.
This issue causes because negative margin set on the cards container:
margin: -0.875em -0.5em
. It is less noticeable in large screen, but huge impact in smaller screen because of em unit as your example.So, with very small height of your sticky container with 14px is totally covered by the cards container.
The cards container need to have negative margin to cover the space taken by the card elements inside.
So, I guess you should wrap your cards within another container and add the top margin or padding.
And your sticky elements also have spaces such as margin, and padding around the box. So, the calculation of the sticky position …