feat: Improve panel positioning in danmuku plugin

This commit is contained in:
Harvey Zack committed 2024-06-13 11:12:23 +08:00
1 parent 685241de57
commit b4e3121917
3 files changed
+19 -5

No files matched your search

@@ -581,8 +581,18 @@ export default class Setting {
const controlRect = $control.getBoundingClientRect();
const panelRect = $panel.getBoundingClientRect();
const playerRect = $player.getBoundingClientRect();
const diff = Math.max(controlRect.right + panelRect.width / 2 - playerRect.right - controlRect.width / 2, 0);
$panel.style.left = `-${panelRect.width / 2 - controlRect.width / 2 + diff}px`;
const half = panelRect.width / 2 - controlRect.width / 2;
const left = playerRect.left - (controlRect.left - half);
const right = controlRect.right + half - playerRect.right;
if (left > 0) {
$panel.style.left = `${-half + left}px`;
} else if (right > 0) {
$panel.style.left = `${-half - right}px`;
} else {
$panel.style.left = `${-half}px`;
}
}
async emit() {