UNPKG

844 BJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.isWindow = isWindow;
7exports["default"] = getScroll;
8
9function isWindow(obj) {
10 return obj !== null && obj !== undefined && obj === obj.window;
11}
12
13function getScroll(target, top) {
14 var _a;
15
16 if (typeof window === 'undefined') {
17 return 0;
18 }
19
20 var method = top ? 'scrollTop' : 'scrollLeft';
21 var result = 0;
22
23 if (isWindow(target)) {
24 result = target[top ? 'pageYOffset' : 'pageXOffset'];
25 } else if (target instanceof Document) {
26 result = target.documentElement[method];
27 } else if (target) {
28 result = target[method];
29 }
30
31 if (target && !isWindow(target) && typeof result !== 'number') {
32 result = (_a = (target.ownerDocument || target).documentElement) === null || _a === void 0 ? void 0 : _a[method];
33 }
34
35 return result;
36}
\No newline at end of file