UNPKG

@hocgin/ahooks-kit

Version:
47 lines (45 loc) 1.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getScrollTop = exports.getScrollHeight = exports.getClientHeight = void 0; exports.getTargetElement = getTargetElement; exports.setScrollTop = void 0; var _hkit = require("@hocgin/hkit"); var setScrollTop = exports.setScrollTop = function setScrollTop(el, top) { // if (el === document || el === document.body) { // top = Math.min(window.pageYOffset, document.documentElement.scrollHeight, document.body.scrollHeight, top); // } // @ts-ignore el.scrollTop = top; }; function getTargetElement(target) { var defaultElement = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined; if (!_hkit.LangKit.isBrowser()) { return undefined; } if (!target) { return defaultElement; } var targetElement; if (_hkit.LangKit.isFunction(target)) { targetElement = target(); } else if ('current' in target) { targetElement = target.current; } else { targetElement = target; } return targetElement; } var getScrollTop = exports.getScrollTop = function getScrollTop(el) { if (el === document || el === document.body) { return Math.max(window.pageYOffset, document.documentElement.scrollTop, document.body.scrollTop); } return el.scrollTop; }; var getScrollHeight = exports.getScrollHeight = function getScrollHeight(el) { return el.scrollHeight || Math.max(document.documentElement.scrollHeight, document.body.scrollHeight); }; var getClientHeight = exports.getClientHeight = function getClientHeight(el) { return el.clientHeight || Math.max(document.documentElement.clientHeight, document.body.clientHeight); };