getDocumentScrollElement.js.flow 938 B

1234567891011121314151617181920212223242526272829303132
  1. /**
  2. * Copyright (c) 2013-present, Facebook, Inc.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @providesModule getDocumentScrollElement
  8. * @typechecks
  9. */
  10. 'use strict';
  11. const isWebkit = typeof navigator !== 'undefined' && navigator.userAgent.indexOf('AppleWebKit') > -1;
  12. /**
  13. * Gets the element with the document scroll properties such as `scrollLeft` and
  14. * `scrollHeight`. This may differ across different browsers.
  15. *
  16. * NOTE: The return value can be null if the DOM is not yet ready.
  17. *
  18. * @param {?DOMDocument} doc Defaults to current document.
  19. * @return {?DOMElement}
  20. */
  21. function getDocumentScrollElement(doc) {
  22. doc = doc || document;
  23. if (doc.scrollingElement) {
  24. return doc.scrollingElement;
  25. }
  26. return !isWebkit && doc.compatMode === 'CSS1Compat' ? doc.documentElement : doc.body;
  27. }
  28. module.exports = getDocumentScrollElement;