@hocgin/ahooks-kit
Version:
40 lines (39 loc) • 1.4 kB
JavaScript
import { LangKit } from "@hocgin/hkit";
export var 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;
};
export function getTargetElement(target) {
var defaultElement = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
if (!LangKit.isBrowser()) {
return undefined;
}
if (!target) {
return defaultElement;
}
var targetElement;
if (LangKit.isFunction(target)) {
targetElement = target();
} else if ('current' in target) {
targetElement = target.current;
} else {
targetElement = target;
}
return targetElement;
}
var 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 = function getScrollHeight(el) {
return el.scrollHeight || Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
};
var getClientHeight = function getClientHeight(el) {
return el.clientHeight || Math.max(document.documentElement.clientHeight, document.body.clientHeight);
};
export { getScrollTop, getScrollHeight, getClientHeight };