UNPKG

rc-hooks

Version:
80 lines (79 loc) 2.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getClientHeight = exports.getScrollHeight = exports.getScrollTop = void 0; exports.isDocumentVisible = isDocumentVisible; exports.isOnline = isOnline; 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; /** * 检查文档是否可见 * * @returns */ function isDocumentVisible() { if (typeof document !== 'undefined' && typeof document.visibilityState !== 'undefined') { return document.visibilityState !== 'hidden'; } return true; } /** * 检查是否在线 * * @returns */ function isOnline() { if (typeof navigator !== 'undefined' && typeof navigator.onLine !== 'undefined') { return navigator.onLine; } return true; }