forked from EnterpriseDB/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgatsby-browser.js
More file actions
30 lines (26 loc) · 799 Bytes
/
gatsby-browser.js
File metadata and controls
30 lines (26 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require('prismjs/themes/prism-okaidia.css');
exports.onRouteUpdate = ({ location }) => scrollToAnchor(location);
/**
*
* @desc - a function to jump to the correct scroll position
* @param {Object} location -
* @param {Number} [mainNavHeight] - the height of any persistent nav -> document.querySelector(`nav`)
*/
function scrollToAnchor(location, mainNavHeight = 0) {
// Check for location so build does not fail
if (location && location.hash) {
try {
const item = document.querySelector(`${location.hash}`);
if (item) {
window.scrollTo({
top: item.offsetTop - mainNavHeight,
behavior: 'smooth',
});
}
} catch (error) {
// if hash is bad exception will be raised
console.error(error);
}
}
return true;
}