tdesign-mobile-vue
Version:
tdesign-mobile-vue
54 lines (49 loc) • 1.77 kB
JavaScript
/**
* tdesign v1.7.0
* (c) 2024 TDesign Group
* @license MIT
*/
;
Object.defineProperty(exports, '__esModule', { value: true });
var getPosition = function getPosition(targetEle, contentEle, placement, clientX) {
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 += 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;
};
exports["default"] = getPosition;
//# sourceMappingURL=getPosition.js.map