mirror of
https://github.com/paricafe/misskey.git
synced 2025-01-17 21:30:49 -06:00
keep popup elements on screen
This commit is contained in:
parent
d1965bf9a3
commit
a4cb7acfa8
2 changed files with 15 additions and 5 deletions
|
@ -107,7 +107,7 @@ onMounted(() => {
|
|||
}
|
||||
|
||||
const rect = props.source.getBoundingClientRect();
|
||||
const x = ((rect.left + (props.source.offsetWidth / 2)) - (300 / 2)) + window.scrollX;
|
||||
const x = Math.max(1, ((rect.left + (props.source.offsetWidth / 2)) - (300 / 2)) + window.scrollX);
|
||||
const y = rect.top + props.source.offsetHeight + window.scrollY;
|
||||
|
||||
top.value = y;
|
||||
|
|
|
@ -15,6 +15,8 @@ export function calcPopupPosition(el: HTMLElement, props: {
|
|||
const contentWidth = el.offsetWidth;
|
||||
const contentHeight = el.offsetHeight;
|
||||
|
||||
const HORIZONTAL_MARGIN = 1;
|
||||
|
||||
let rect: DOMRect;
|
||||
|
||||
if (props.anchorElement) {
|
||||
|
@ -36,9 +38,11 @@ export function calcPopupPosition(el: HTMLElement, props: {
|
|||
left -= (el.offsetWidth / 2);
|
||||
|
||||
if (left + contentWidth - window.scrollX > window.innerWidth) {
|
||||
left = window.innerWidth - contentWidth + window.scrollX - 1;
|
||||
left = window.innerWidth - contentWidth + window.scrollX - HORIZONTAL_MARGIN;
|
||||
}
|
||||
|
||||
left = Math.max(HORIZONTAL_MARGIN, left);
|
||||
|
||||
return [left, top];
|
||||
};
|
||||
|
||||
|
@ -57,9 +61,11 @@ export function calcPopupPosition(el: HTMLElement, props: {
|
|||
left -= (el.offsetWidth / 2);
|
||||
|
||||
if (left + contentWidth - window.scrollX > window.innerWidth) {
|
||||
left = window.innerWidth - contentWidth + window.scrollX - 1;
|
||||
left = window.innerWidth - contentWidth + window.scrollX - HORIZONTAL_MARGIN;
|
||||
}
|
||||
|
||||
left = Math.max(HORIZONTAL_MARGIN, left);
|
||||
|
||||
return [left, top];
|
||||
};
|
||||
|
||||
|
@ -75,10 +81,12 @@ export function calcPopupPosition(el: HTMLElement, props: {
|
|||
top = props.y;
|
||||
}
|
||||
|
||||
left = Math.max(HORIZONTAL_MARGIN, left);
|
||||
|
||||
top -= (el.offsetHeight / 2);
|
||||
|
||||
if (top + contentHeight - window.scrollY > window.innerHeight) {
|
||||
top = window.innerHeight - contentHeight + window.scrollY - 1;
|
||||
top = window.innerHeight - contentHeight + window.scrollY - HORIZONTAL_MARGIN;
|
||||
}
|
||||
|
||||
return [left, top];
|
||||
|
@ -106,8 +114,10 @@ export function calcPopupPosition(el: HTMLElement, props: {
|
|||
top -= (el.offsetHeight / 2);
|
||||
}
|
||||
|
||||
left = Math.max(HORIZONTAL_MARGIN, left);
|
||||
|
||||
if (top + contentHeight - window.scrollY > window.innerHeight) {
|
||||
top = window.innerHeight - contentHeight + window.scrollY - 1;
|
||||
top = window.innerHeight - contentHeight + window.scrollY - HORIZONTAL_MARGIN;
|
||||
}
|
||||
|
||||
return [left, top];
|
||||
|
|
Loading…
Reference in a new issue