Browse Source

Prevent upgrade tooltips from going off the screen

tags/v0.0.3
Fen Dweller 5 years ago
parent
commit
b932ebdd48
2 changed files with 14 additions and 2 deletions
  1. +1
    -0
      gorge.css
  2. +13
    -2
      gorge.js

+ 1
- 0
gorge.css View File

@@ -3,6 +3,7 @@ body {
user-select: none; user-select: none;
-moz-user-select: none; -moz-user-select: none;
touch-action: manipulation; touch-action: manipulation;
overflow: hidden;
} }


body.dark { body.dark {


+ 13
- 2
gorge.js View File

@@ -649,8 +649,21 @@ function upgradeTooltip(id, event) {
fillTooltip("upgrade", "prereqs", renderPrereqs(upgrades[id].prereqs)); fillTooltip("upgrade", "prereqs", renderPrereqs(upgrades[id].prereqs));


let yOffset = tooltip.parentElement.getBoundingClientRect().y; let yOffset = tooltip.parentElement.getBoundingClientRect().y;
let tooltipSize = tooltip.getBoundingClientRect().height;


let yTrans = Math.round(event.clientY - yOffset); let yTrans = Math.round(event.clientY - yOffset);

var body = document.body,
html = document.documentElement;

var height = Math.max(window.innerHeight);

yTrans = Math.min(yTrans, height - tooltipSize - 150);

console.log(height);
console.log(yOffset);
console.log(yTrans);

tooltip.style.setProperty("transform", "translate(-220px, " + yTrans + "px)"); tooltip.style.setProperty("transform", "translate(-220px, " + yTrans + "px)");
} }


@@ -693,8 +706,6 @@ function buildingTooltip(id, event) {
fillTooltip("building", "cost", render(costOfBuilding(id)) + " food"); fillTooltip("building", "cost", render(costOfBuilding(id)) + " food");
fillTooltip("building", "prod", prodSummary(id)); fillTooltip("building", "prod", prodSummary(id));


let yOffset = tooltip.parentElement.getBoundingClientRect().y;

let xPos = tooltip.parentElement.getBoundingClientRect().x - 450; let xPos = tooltip.parentElement.getBoundingClientRect().x - 450;
// wow browsers are bad // wow browsers are bad


Loading…
Cancel
Save