UNPKG

rc-hooks

Version:
56 lines (55 loc) 1.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getClientHeight = exports.getScrollHeight = exports.getScrollTop = void 0; var ut2_1 = require("ut2"); /** * 获取垂直滚动的像素数 * * @param el 滚动容器,默认 window * @returns */ var getScrollTop = function (el) { if (el === void 0) { el = window; } if (!ut2_1.isBrowser || !el) { return 0; } if ((0, ut2_1.isWindow)(el)) { return window.scrollY; } return el.scrollTop; }; exports.getScrollTop = getScrollTop; /** * 获取元素内容高度,包括由于溢出导致的视图中不可见内容 * * @param el 滚动容器,默认 window * @returns */ var getScrollHeight = function (el) { if (el === void 0) { el = window; } if (!ut2_1.isBrowser || !el) { return 0; } if ((0, ut2_1.isWindow)(el)) { return document.documentElement.scrollHeight; } return el.scrollHeight; }; exports.getScrollHeight = getScrollHeight; /** * 获取元素内部的高度,包含内边距,但不包括水平滚动条、边框和外边距 * * @param el 滚动容器,默认 window * @returns */ var getClientHeight = function (el) { if (el === void 0) { el = window; } if (!ut2_1.isBrowser || !el) { return 0; } if ((0, ut2_1.isWindow)(el)) { return document.documentElement.clientHeight; } return el.clientHeight; }; exports.getClientHeight = getClientHeight;