UNPKG

tdesign-mobile-vue

Version:
50 lines (47 loc) 1.76 kB
/** * tdesign v1.9.3 * (c) 2025 TDesign Group * @license MIT */ var getPosition = function getPosition(targetEle, contentEle, placement, clientX, clientY) { var targetRect = targetEle.getBoundingClientRect(); var contentRect = contentEle.getBoundingClientRect(); var position = { top: document.documentElement.scrollTop, left: document.documentElement.scrollLeft }; if (targetRect && contentRect) { var dWidth = targetRect.width - contentRect.width; switch (placement) { case "top": position.left += targetRect.left + dWidth / 2; position.top += targetRect.top - contentRect.height - 16; break; case "bottom": position.left += targetRect.left + dWidth / 2; position.top += targetRect.top + targetRect.height; break; case "mouse": position.left += Number(clientX); position.top += typeof clientY !== "undefined" ? Number(clientY) + 16 : targetRect.top + targetRect.height + 8; break; } if (placement === "mouse") { var edges = { top: document.documentElement.scrollTop, left: document.documentElement.scrollLeft, right: document.documentElement.scrollLeft + document.documentElement.clientWidth, bottom: document.documentElement.scrollTop + document.documentElement.clientHeight }; if (position.top > edges.bottom - contentRect.height) { position.top = document.documentElement.scrollTop + targetRect.top - contentRect.height - 8; } if (position.left > edges.right - contentRect.width) { position.left = edges.right - contentRect.width; } } } return position; }; export { getPosition as default }; //# sourceMappingURL=getPosition.js.map