scroll-to-anchor
Advanced tools
Comparing version 1.0.0 to 1.1.0
module.exports = scrollToAnchor | ||
function scrollToAnchor (anchor) { | ||
function scrollToAnchor (anchor, options) { | ||
if (anchor) { | ||
try { | ||
var el = document.querySelector(anchor) | ||
if (el) el.scrollIntoView(true) | ||
if (el) el.scrollIntoView(options) | ||
} catch (e) {} | ||
} | ||
} |
@@ -5,3 +5,3 @@ { | ||
"repository": "yoshuawuyts/scroll-to-anchor", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"scripts": { | ||
@@ -8,0 +8,0 @@ "deps": "dependency-check . && dependency-check . --extra --no-dev", |
@@ -11,9 +11,12 @@ # scroll-to-anchor [![stability][0]][1] | ||
scrollToAnchor(window.location.hash) | ||
scrollToAnchor(window.location.hash, { behavior: 'smooth' }) | ||
``` | ||
## API | ||
### `scrollToAnchor(anchor)` | ||
### `scrollToAnchor(anchor, options)` | ||
Scroll to an anchor if possible. Does nothing if no anchor is provided or if the | ||
anchor doesn't exist on the page. | ||
You can also specify the same options as the [scrollIntoView](https://developer.mozilla.org/en/docs/Web/API/Element/scrollIntoView#Parameters) method which allows for more positioning options and scroll behaviour changes. | ||
## License | ||
@@ -20,0 +23,0 @@ [MIT](https://tldrlegal.com/license/mit-license) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3699
36