I've seen this kind of behaviour on a few sites. I thought it was achieved by having the position fixed on the element, as soon as JS detected that the element was moving out of the document window.
There's a time and a place for this sort of thing. I personally get a little annoyed with fixed headers as it can break text paging. Text gets hidden under the header. When you hit page-down you get another page worth of text but the fixed element obscures the text.
Can position: sticky help with something like that?