getDocumentScrollElement.js 892 B

12345678910111213141516171819202122232425262728293031
  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. * @typechecks
  8. */
  9. 'use strict';
  10. var isWebkit = typeof navigator !== 'undefined' && navigator.userAgent.indexOf('AppleWebKit') > -1;
  11. /**
  12. * Gets the element with the document scroll properties such as `scrollLeft` and
  13. * `scrollHeight`. This may differ across different browsers.
  14. *
  15. * NOTE: The return value can be null if the DOM is not yet ready.
  16. *
  17. * @param {?DOMDocument} doc Defaults to current document.
  18. * @return {?DOMElement}
  19. */
  20. function getDocumentScrollElement(doc) {
  21. doc = doc || document;
  22. if (doc.scrollingElement) {
  23. return doc.scrollingElement;
  24. }
  25. return !isWebkit && doc.compatMode === 'CSS1Compat' ? doc.documentElement : doc.body;
  26. }
  27. module.exports = getDocumentScrollElement;