jonaskuske / smoothscroll-anchor-polyfill

⚓ Apply smooth scroll to anchor links, polyfill scroll-behavior
https://jonaskuske.github.io/smoothscroll-anchor-polyfill
MIT License
41 stars 3 forks source link

Expose shouldSmoothscroll() as part of public API #15

Closed jonaskuske closed 5 years ago

jonaskuske commented 5 years ago

Giving users access to smoothscrollAnchorPolyfill.shouldSmoothscroll() would allow userland implementations for JS scroll APIs to stay in sync with the behavior detected by this polyfill.

Something along the lines of:

const scroll = scrollTo = function (opts = {}) {
  if (!opts.behavior && shouldSmoothscroll()) {
    opts.behavior = 'smooth'
  }
  const container = this instanceof Element ? this : window
  container.scroll(opts)
}

Renaming the API should be considered too, as well as maybe returning the detected behavior as a string (smooth|auto|initial|inherit|unset) instead of a simple boolean.