JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7622
  • Score
    100M100P100Q117696F
  • License MIT

Feature detected access to the scroller element

Package Exports

  • scroll-doc

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (scroll-doc) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

scrollDoc

Feature detected access to the scroller element

import scrollDoc from 'scroll-doc';

const scrollElement = scrollDoc();

// scroll to the top
scrollElement.scrollTop = 0;

How it works

ScrollDoc uses feature detection to detect which element is valid for scrolling the document. It attempts to scroll 1px using document.documentElement if it succeeds, it will reset document.documentElement to it's original scroll position and return document.documentElement; if it fails, it will return document.body. The result is cached and the cached value is returned on subsequent calls.