UNPKG

gatsby-plugin-smoothscroll

Version:

Polyfilled smooth scrolling behavior and helper function for Gatsby sites.

35 lines (28 loc) 1.05 kB
"use strict"; exports.__esModule = true; exports["default"] = void 0; /** * Smooth scrolling onClick event handler * @param {string} selector argument will be passed to `querySelector`, usually an HTML id * @param {string} [blockPosition='start'] argument will be used to determine position where will be scrolled to (start, center, end, nearest) * @returns {boolean} false if `document.querySelector` doesn't find a match, otherwise true */ var scrollTo = function scrollTo(selector, blockPosition) { if (blockPosition === void 0) { blockPosition = 'start'; } var element = document.querySelector(selector); if (element) { element.scrollIntoView({ behavior: 'smooth', block: blockPosition }); return true; } if (process.env.NODE_ENV !== 'production') { console.warn("gatsby-plugin-smoothscroll:\n The selector: '%s' wasn't found in the document.\n Make sure you pass in a valid CSS selector string.", selector); } return false; }; var _default = scrollTo; exports["default"] = _default;