getScroll.js 776 B

12345678910111213141516171819202122
  1. export function isWindow(obj) {
  2. return obj !== null && obj !== undefined && obj === obj.window;
  3. }
  4. export default function getScroll(target, top) {
  5. if (typeof window === 'undefined') {
  6. return 0;
  7. }
  8. var method = top ? 'scrollTop' : 'scrollLeft';
  9. var result = 0;
  10. if (isWindow(target)) {
  11. result = target[top ? 'pageYOffset' : 'pageXOffset'];
  12. } else if (target instanceof Document) {
  13. result = target.documentElement[method];
  14. } else if (target) {
  15. result = target[method];
  16. }
  17. if (target && !isWindow(target) && typeof result !== 'number') {
  18. var _documentElement;
  19. result = (_documentElement = (target.ownerDocument || target).documentElement) === null || _documentElement === void 0 ? void 0 : _documentElement[method];
  20. }
  21. return result;
  22. }