Why doesn't Discourse use position:sticky for the top header?

Continuing the discussion from How to finely scroll out custom header?:

https://caniuse.com/#feat=css-sticky

The behavior that the d-header is doing, where markup placed before it scrolls of the screen but the header itself does not, is implemented using a JavaScript onscroll handler. This is a common-enough feature that evergreen browsers implement it build-in now, with no glitching.

2 Likes

We have talked about this at one point, but we still need to support IE11. Sadly if you toggle to “usage relative” on caniuse IE11 is still more common than Edge and even desktop Safari… a lot of corporate environments are stuck with it.

Not sure if the switch would be worth it if we have to maintain the JS version for IE anyway… it’s alternatively possible to consider a sticky header as an enhancement rather than a must-have feature and just drop it entirely for old browsers… but it works right now, so that would be removing existing functionality.

7 Likes

Using position:sticky can help avoid a cornucopia of jank bugs related to slowly-dispatched scroll events and measuring things. Here’s another one:

I admit it’s not a big deal, but it would provide actual improvements for browsers that support it, not just warm fuzzies.

2 Likes

That bug is completely unrelated to sticky, it happens cause of this

It will eventually go away, oddly enough, when we rewrite our timeline in ember, cause now we pay a big tax on

It is possible, I guess we can work around the chrome timer bug by adding sticky to chrome for the timeline :slight_smile:

2 Likes

Yeah, that’s almost exactly what I meant, though I figured if you’re going to implement it, you might as well use position: sticky on every browser that supports it (that’s most of them other than IE11).

Yeah but the problem here is that we would need to shift the “sticky” when you reach the end of a topic (I think) from the top of the container, to the bottom. To do that we need an ember run loop even, which will be delayed, so it is back to square one?

1 Like

No. Here’s a close emulation of the Discourse timeline’s positioning with no JavaScript whatsoever:

https://jsfiddle.net/d3Lsq7e8/

Copied locally
<!DOCTYPE html>
<h1>Lorem Ipsum - All the facts</h1>
<div class=conversation>
<div style="width:1em;position:sticky;float:right;top:0;bottom:0">
S<br>
I<br>
D<br>
E<br>
B<br>
A<br>
R<br>
</div>
<div style="overflow:hidden">
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
<h2>
Where does it come from?
</h2>
<p>
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
</p>
<p>
The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
</p>
<h2>
Why do we use it?
</h2>
<p>
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
</p>
<h2>
Where can I get some?
</h2>
<p>
There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.
</p>
</div>
</div>
<div class=footer>
<h1>
Related posts
</h1>
<h2>
The standard Lorem Ipsum passage, used since the 1500s
</h2>
<p>
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
</p>
<h2>
Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC
</h2>
<p>
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"
</p>
</div>
5 Likes

Interesting, how would we vanish these 2 buttons though?

image

It could be done with an appropriately-positioned high-z-index “cover DIV”, but TBH, that’s overkill. I’m trying to avoid weirdly-overlapping stuff; I’m not trying to remove scroll-triggered JavaScript entirely. If it takes two seconds for those buttons to disappear, that will make Discourse feel slow, not broken.

4 Likes

OK I am very open to making this change provided we have the IE11 polyfill in a dedicated file and that the polyfill is no slower than our current implementation, something like this could work: https://github.com/wilddeer/stickyfill

Overall this removes code from Discourse which is nice.

7 Likes

We use position: sticky; for the header and timeline now! :tada:

6 Likes