@uehreka/gatsby-plugin-anchor-links
Version:
Gatsby plugin for using anchor links with a Gatsby Link component (this one supports gatsby-plugin-transition-link).
33 lines (25 loc) • 849 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.onRouteUpdate = void 0;
var _utils = require("./utils");
var scrollTimeout = null;
var onRouteUpdate = function onRouteUpdate(_ref, _ref2) {
var location = _ref.location;
var _ref2$offset = _ref2.offset,
offset = _ref2$offset === void 0 ? 0 : _ref2$offset;
cancelAnimationFrame(scrollTimeout);
scrollTimeout = requestAnimationFrame(function () {
var windowHash;
if (_utils.isBrowser) {
window.gatsby_scroll_offset = offset;
windowHash = window.gatsby_scroll_hash;
}
Boolean(windowHash) ? (0, _utils.scroller)(windowHash, offset) : (0, _utils.checkHash)(location, offset);
if (_utils.isBrowser && windowHash) {
window.gatsby_scroll_hash = undefined;
}
});
};
exports.onRouteUpdate = onRouteUpdate;