scroll-polyfill
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

scroll-polyfill

Coverage Status npm version

Scroll options polyfill:

  • Add ScrollToOptions polyfill for Element.protype.{scroll|scrollTo|scrollBy}, window.{scroll|scrollTo|scrollBy}
  • Add ScrollIntoViewOptions polyfill for Element.prototype.scrollIntoView
  • Smooth spring-based scrolling

Install

npm install scroll-polyfill

Usage

Polyfill

import 'scroll-polyfill/auto'

// OR:
import scrollPolyfill from 'scroll-polyfill'

scrollPolyfill()

// or you can force the polyfill (skiping feature detection)
scrollPolyfill({force: true})

// use ScrollToOptions
window.scroll({behavior: 'smooth', left: 100, top: 100})
scroller.scrollBy({behavior: 'smooth', top: 100})

// use ScrollIntoViewOptions
scrollerChild.scrollIntoView({
  behavior: 'smooth',
  block: 'nearest',
  inline: 'start',
})
document.body.scrollIntoView(false)

Ponyfill

These methods have smooth spring-based scrolling and are recommended even if polyfill is not installed:

import {scrollTo, scrollBy, scrollIntoView} from 'scroll-polyfill'

scrollTo(window, {behavior: 'smooth', top: 100})
scrollBy(document.scrollingElement, {behavior: 'smooth', top: 100})
scrollIntoView(scrollerChild, {
  behavior: 'smooth',
  block: 'nearest',
  inline: 'start',
})

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.1
    907
    • latest

Version History

Package Sidebar

Install

npm i scroll-polyfill

Weekly Downloads

1,003

Version

1.0.1

License

MIT

Unpacked Size

20.6 kB

Total Files

9

Last publish

Collaborators

  • ambarli