Files
shields/gatsby-browser.js
2019-02-20 16:34:50 -05:00

17 lines
366 B
JavaScript

// Adapted from https://github.com/gatsbyjs/gatsby/issues/8413
function scrollToElementId(id) {
const el = document.querySelector(id)
if (el) {
return window.scrollTo(0, el.offsetTop - 20)
} else {
return false
}
}
export function onRouteUpdate({ location: { hash } }) {
if (hash) {
window.setTimeout(() => scrollToElementId(hash), 10)
}
}