Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix menu scale pos problem #2734 #2767

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vtable",
"comment": "fix: fix menu scale pos problem #2734",
"type": "none"
}
],
"packageName": "@visactor/vtable"
}
16 changes: 12 additions & 4 deletions packages/vtable/src/components/menu/dom/logic/MenuElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,11 +499,19 @@ export class MenuElement {
rootElementLeft = referencePosition.rect.right - rootElementWidth;
rootElementTop = referencePosition.rect.bottom;
}

// 获取元素的边界矩形
const rect = element.getBoundingClientRect();

// 计算缩放比例
const scaleX = rect.width / element.offsetWidth;
const scaleY = rect.height / element.offsetHeight;

// rootElementLeft = position.x - rootElementWidth;
// let leftStyle = rootElementLeft;
// 检测下方能否容纳,不能容纳向上偏移
if (rootElementTop + rootElementHeight > containerHeight) {
rootElementTop = containerHeight - rootElementHeight;
if (rootElementTop * scaleY + rootElementHeight > containerHeight) {
rootElementTop = (containerHeight - rootElementHeight) / scaleY;
// rootElementLeft += rootElementWidth - 2;
}
// 偏移后上方超出canvas范围,居中显示
Expand All @@ -515,8 +523,8 @@ export class MenuElement {
// 判断如果超出左右范围则靠边显示
if (rootElementLeft < 0) {
rootElementLeft = 0;
} else if (rootElementLeft + rootElementWidth > containerWidth) {
rootElementLeft = containerWidth - rootElementWidth;
} else if (rootElementLeft * scaleX + rootElementWidth > containerWidth) {
rootElementLeft = (containerWidth - rootElementWidth) / scaleX;
}
rootElement.style.left = `${rootElementLeft}px`;

Expand Down
Loading