move tooltip away from edges

This commit is contained in:
Damien Elmes 2020-06-29 15:05:08 +10:00
parent 72609bee18
commit 4a04ccd96c

View file

@ -12,9 +12,14 @@ function showTooltipInner(msg: string, x: number, y: number): void {
document.body.appendChild(tooltipDiv);
}
tooltipDiv.innerHTML = msg;
tooltipDiv.style.right = `${document.body.clientWidth - x + 10}px`;
tooltipDiv.style.top = `${y + 20}px`;
// move tooltip away from edge as user approaches right side
const shiftLeftAmount = Math.round(
tooltipDiv.clientWidth * 1.2 * (x / document.body.clientWidth)
);
tooltipDiv.style.left = `${x + 40 - shiftLeftAmount}px`;
tooltipDiv.style.top = `${y + 40}px`;
tooltipDiv.style.opacity = "1";
}