fix: 修复panel菜单position位置的问题

This commit is contained in:
qianfengg 2021-05-01 16:12:25 +08:00
parent c5490fdf4d
commit c66fb8b036
2 changed files with 17 additions and 1 deletions

View File

@ -41,6 +41,11 @@
// '微软雅黑',
// ]
// 这行代码用来测试不同屏幕宽度panel菜单的位置
// editor.config.menus = [
// 'image'
// ]
editor.config.showFullScreen = true
editor.create()
</script>

View File

@ -62,7 +62,18 @@ class Panel {
const rect = menu.editor.$toolbarElem.getBoundingClientRect()
const menuRect = menu.$elem.getBoundingClientRect()
const top = rect.height + rect.top - menuRect.top
const left = (rect.width - width) / 2 + rect.left - menuRect.left
let left = (rect.width - width) / 2 + rect.left - menuRect.left
const offset = 300 // icon与panel菜单距离偏移量暂定 300
if (Math.abs(left) > offset) {
// panel菜单离工具栏icon过远时让panel菜单出现在icon正下方处理边界逻辑
if (menuRect.left < document.documentElement.clientWidth / 2) {
// icon在左侧
left = -menuRect.width / 2
} else {
// icon在右侧
left = -width + menuRect.width / 2
}
}
$container
.css('width', width + 'px')