diff --git a/docs/app/utils.js b/docs/app/utils.js index aa5d514180..0967dd0082 100644 --- a/docs/app/utils.js +++ b/docs/app/utils.js @@ -15,6 +15,14 @@ export const parentComponents = _.flow( _.sortBy('_meta.name') )(semanticUIReact) +const mathSign = Math.sign || function(x) { + x = +x; + if (x === 0 || isNaN(x)) { + return x; + } + return x > 0 ? 1 : -1; + } + /** * Get the Webpack Context for all doc site examples. */ @@ -27,6 +35,7 @@ export const semanticUICSSRepoURL = 'https://github.com/Semantic-Org/Semantic-UI export const scrollToAnchor = () => { const anchor = location.hash && document.querySelector(location.hash) + const offsetY = window.scrollY || window.pageYOffset // no scroll to target, stop if (!anchor) return @@ -37,9 +46,9 @@ export const scrollToAnchor = () => { if (elementTop === 0) return // hit max scroll boundaries, stop - const isScrolledToTop = scrollY === 0 - const isScrolledToBottom = scrollY + document.body.clientHeight === document.body.scrollHeight - const scrollStep = Math.ceil((Math.abs(elementTop / 8))) * Math.sign(elementTop) + const isScrolledToTop = offsetY === 0 + const isScrolledToBottom = offsetY + document.body.clientHeight === document.body.scrollHeight + const scrollStep = Math.ceil((Math.abs(elementTop / 8))) * mathSign(elementTop) if (isScrolledToBottom && scrollStep > 0 || isScrolledToTop && scrollStep < 0) return