I am trying to achieve an effect similar to what this page shows: When the top of the window reaches the top of a particular container, I want it to get sticked in the top of the window.
I have found this question in SO which deals with this behaviour. But I am not looking the container to get stick when the user reaches a particular px, but when the user reaches the start of a container. I want it this way because the size between the top of the page and the top of the container can vary.
My questions are:
-> How can I know when I have reached the top of a particular container.
-> If that container has the position: relative, because it has several elements inside which are relatively positioned, and therefore I can't use fixed, what would I do?
-> How can I reset the container once I scroll up and I reach the same point where it was positioned?
Thanks