X Tutup
The Wayback Machine - https://web.archive.org/web/20210122212113/https://github.com/ambar/scroll-polyfill
Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

scroll-polyfill

Scroll opitons polyfill:

  • Add ScrollToOptions polyfill for Element.protype.{scroll|scrollTo|scrollBy}, window.{scroll|scrollTo|scrollBy}
  • Add ScrollIntoViewOptions polyfill for Element.protype.scrollIntoView

Install

npm install scroll-polyfill

Usage

Polyfill

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

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',
})
X Tutup