getScroll.js 892 B

1234567891011121314151617181920212223242526272829
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = getScroll;
  6. exports.isWindow = isWindow;
  7. function isWindow(obj) {
  8. return obj !== null && obj !== undefined && obj === obj.window;
  9. }
  10. function getScroll(target, top) {
  11. if (typeof window === 'undefined') {
  12. return 0;
  13. }
  14. var method = top ? 'scrollTop' : 'scrollLeft';
  15. var result = 0;
  16. if (isWindow(target)) {
  17. result = target[top ? 'pageYOffset' : 'pageXOffset'];
  18. } else if (target instanceof Document) {
  19. result = target.documentElement[method];
  20. } else if (target) {
  21. result = target[method];
  22. }
  23. if (target && !isWindow(target) && typeof result !== 'number') {
  24. var _documentElement;
  25. result = (_documentElement = (target.ownerDocument || target).documentElement) === null || _documentElement === void 0 ? void 0 : _documentElement[method];
  26. }
  27. return result;
  28. }