From ffc497cdbd75fb52590a00b9912f67f6484f1565 Mon Sep 17 00:00:00 2001 From: ReiMerc Date: Mon, 6 Feb 2023 13:23:12 +0100 Subject: [PATCH] Don't mess up coordinates when resizing image --- index.html | 3 ++- script.js | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 3cb311e..1602787 100644 --- a/index.html +++ b/index.html @@ -1,7 +1,7 @@ - noob + Zipcode Finder @@ -13,3 +13,4 @@ + diff --git a/script.js b/script.js index 42ea703..606aea0 100644 --- a/script.js +++ b/script.js @@ -1,3 +1,5 @@ +"use strict"; + var mouseX, mouseY; denmark.onmousemove = event => { @@ -8,8 +10,8 @@ denmark.onmousemove = event => { mouseX = event.x - rect.left; mouseY = event.y - rect.top; - var coordX = mouseX * 0.00875 + 6; - var coordY = Math.abs(mouseY * 0.0052 - 58); + var coordX = mouseX / event.target.clientWidth * 8 + 6.2; + var coordY = Math.abs(mouseY / event.target.clientHeight * 3.6 - 57.93); coords.innerHTML = `${coordX}
${coordY}`; @@ -46,3 +48,4 @@ function onZipError() { zip.style.top = (mouseY+3) + "px"; zip.style.display = "block"; } +