Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Sticky header disappears by momentum scroll #1070

Conversation

rnitta
Copy link
Contributor

@rnitta rnitta commented Oct 18, 2019

In the default theme, there is sticky header.

sticky_header

The header will be hidden when the page is scrolled down. like:

スクリーンショット 2019-10-18 15 28 58

This behavior make a problem with momentum scroll.
With momentum scroll, document.scrollingElement.scrollTop can be negative number, so scrolling up above the upper limit of a page makes such logs below:

[Log] document.scrollingElement.scrollTop:0 (book.js, line 593)
[Log] document.scrollingElement.scrollTop:-1 (book.js, line 593)
[Log] document.scrollingElement.scrollTop:-2 (book.js, line 593)
[Log] document.scrollingElement.scrollTop:-4 (book.js, line 593)
[Log] document.scrollingElement.scrollTop:-10 (book.js, line 593)
[Log] document.scrollingElement.scrollTop:-12 (book.js, line 593)
[Log] document.scrollingElement.scrollTop:-11 (book.js, line 593)
[Log] document.scrollingElement.scrollTop:-10 (book.js, line 593)
[Log] document.scrollingElement.scrollTop:-7 (book.js, line 593)
[Log] document.scrollingElement.scrollTop:-4 (book.js, line 593)
[Log] document.scrollingElement.scrollTop:-2 (book.js, line 593)
[Log] document.scrollingElement.scrollTop:-1 (book.js, line 593)
[Log] document.scrollingElement.scrollTop:0 (book.js, line 593)

The last part of logs is detected as "scrolling down", so

Oct-18-2019 15-38-59

the header disappear.
I Fixed it by coercing the negative value of document.scrollingElement.scrollTop into 0.

this problem can be reproduce with macOS safari and iOS safari and maybe other momentum scrollable browsers.

Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing! Glad to see someone fix it.

@Dylan-DPC This could be merged now.

@Dylan-DPC-zz Dylan-DPC-zz merged commit a592da3 into rust-lang:master Oct 19, 2019
@jdx
Copy link

jdx commented Nov 1, 2019

if this drives you nuts because the header is hiding the top part you're trying to read and the book you're reading does not yet have this patch, add this custom css (with stylus or something) to make the header always visible:

html:not(.sidebar-visible) #menu-bar:not(:hover).folded > #menu-bar-sticky-container {
    transform: none;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants