UNPKG

fastlion-amis

Version:

一种MIS页面生成工具

41 lines (40 loc) 1.89 kB
"use strict"; /** * 修改自 https://github.com/react-bootstrap/dom-helpers/blob/master/src/offset.ts */ Object.defineProperty(exports, "__esModule", { value: true }); var getFirstScrollParentElement = function (node) { var overFlowStyle = getComputedStyle(node).overflow; // 超出展示的样式 if (['auto', 'scroll'].includes(overFlowStyle)) return node; // 如果是滚动样式直接返回 if (!node.parentElement) return node; // 如果没有父元素 直接返回 return getFirstScrollParentElement(node.parentElement); // 递归执行 }; /** * Returns the offset of a given element, including top and left positions, width and height. * * @param node the element */ function offset(node, toolScroll) { if (toolScroll === void 0) { toolScroll = false; } var doc = node === null || node === void 0 ? void 0 : node.ownerDocument; var box = { top: 0, left: 0, height: 0, width: 0 }; var docElem = doc && doc.documentElement; var firstClostestNode = node ? getFirstScrollParentElement(node) : docElem; // 获取最接近的滚动元素 // Make sure it's not a disconnected DOM node if (!docElem || !docElem.contains(node)) return box; if (node.getBoundingClientRect !== undefined) box = node.getBoundingClientRect(); // console.log('高度参数比较', firstClostestNode, node, box, box.top, firstClostestNode.scrollTop, box.top + firstClostestNode.scrollTop, docElem.scrollTop, docElem.clientTop) box = { top: box.top + (toolScroll ? 0 : firstClostestNode.scrollTop) - (docElem.clientTop || 0), left: box.left + (toolScroll ? 0 : firstClostestNode.scrollLeft) - (docElem.clientLeft || 0), width: box.width, height: box.height }; return box; } exports.default = offset; //# sourceMappingURL=./utils/offset.js.map