You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When navigating to an internal link of a page (e.g. #something), I think that the headroom should always be shown until the scrolling ends. The reason behind this is that elements with IDs are usually positioned to accommodate a fixed header above themselves. Pinning the headroom during a programmatically invoked scroll would also improve consistency with the proposed non-JS mode (please see #125 for further details).
Also, in order to support smooth scrolling behavior, continuous inspection of window.pageYOffset is required. I wrote the following code snippet to solve the aforementioned problems:
constSCROLL_MAX_FRAMES_WITHOUT_PAGE_OFFSET_CHANGE=30;classHeadroomextendsReact.Component{constructor(){// ...this.setState({downTolerance: this.props.downTolerance,});// Avoid problems with server-side renderingif(typeofwindow!=='undefined'){// Keep headroom pinned during smooth scrollwindow.addEventListener('hashchange',()=>{// Disable headroom unpinning caused by scrolling downwardsthis.setState({downTolerance: Number.POSITIVE_INFINITY});this.headroom.pin();// Re-enable headroom unpinning after smooth scrollletprevPageYOffset=window.pageYOffset;letframesWithoutPageOffsetChange=0;constcheckScrollState=()=>{// Check whether scrolling is still in progressif(window.pageYOffset!==prevPageYOffset){prevPageYOffset=window.pageYOffset;framesWithoutPageOffsetChange=0;}else{framesWithoutPageOffsetChange+=1;if(framesWithoutPageOffsetChange>SCROLL_MAX_FRAMES_WITHOUT_PAGE_OFFSET_CHANGE){// Restore downTolerance of the headroomthis.setState({downTolerance: this.props.downTolerance});return;}}raf(checkScrollState);};raf(checkScrollState);});}}}
A customized implementation of the snippet can be found here.
The text was updated successfully, but these errors were encountered:
When navigating to an internal link of a page (e.g.
#something
), I think that the headroom should always be shown until the scrolling ends. The reason behind this is that elements with IDs are usually positioned to accommodate a fixed header above themselves. Pinning the headroom during a programmatically invoked scroll would also improve consistency with the proposed non-JS mode (please see #125 for further details).Also, in order to support smooth scrolling behavior, continuous inspection of
window.pageYOffset
is required. I wrote the following code snippet to solve the aforementioned problems:A customized implementation of the snippet can be found here.
The text was updated successfully, but these errors were encountered: