A simple dependency-free JavaScript smooth scroll helper. Enables scrolling between any DOM elements, including within positioned and specifically styled elements. React friendly!
- Vanilla JS - Performs a smooth scroll example on the document.body.
- React - Performs a smooth scroll between three elements within an absolute element of fixed height.
-
Via NPM:
npm install smooth-jumper --save
. -
Or use the
lib/smooth-jumper.min.js
file as an external script. Usage:smoothJump(containerEl, targetEl, options = {});
-
Exports a single function with 3 arguments:
- The DOM container element
- The DOM target element
- Options - JS Object (options listed below)
- 'easing' for easing types:
ease-in-out
,ease-in-cubic
,in-out-quint
- 'duration': Integer (in milliseconds; default is 500ms)
- 'offset': Integer (in pixels; default is 0)
npm run dev
- Entry route issrc/examples/index.js
. This loads the React app with Hot Module Replacement (hot reloading).npm run build
- Builds the NPM production version smooth-jumper.js in thelib
directory.npm run build:min
- Builds the minified production version smooth-jumper.min.js in thelib
directory.npm run build:examples
- Builds the static JavaScript and SCSS files. The following files are created in the *examples
directory:bundle.js
andstyle.css
.npm run lint
- Runs an ES lint to check everything's nice and tidy.
MIT