diff options
| author | ache <ache@ache.one> | 2024-07-21 05:49:20 +0200 |
|---|---|---|
| committer | ache <ache@ache.one> | 2024-07-21 05:49:20 +0200 |
| commit | 767a22ae89a485a981f1368c33e20b551b1c7099 (patch) | |
| tree | ef085eed12ed04466533a4c37abe9197afe03304 | |
| parent | Declare variable with const (diff) | |
Fix the tooltip position when the cursor is on the screen on DOM load
| -rw-r--r-- | src/App.svelte | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/App.svelte b/src/App.svelte index 4c764b6..e17eba3 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -162,27 +162,29 @@ */ const deps = fr_svg.getElementsByTagName("path"); + function updatePosition(e) { + if(currentDepGuessed == -1) { + info.style.top = `${e.pageY - 70}px`; + info.style.left = `${e.pageX - 0}px`; + } + } + for(let dep of deps) { if(dep.id.startsWith("dep_")) { const code = dep.id.slice(4).replace("-bis", ""); - dep.addEventListener("mouseenter", () => { + dep.addEventListener("mouseenter", e => { if(currentDepGuessed == -1) { info.classList.add("active") info.innerHTML = `<b>${departements[code]['name']}</b> (${code})` + updatePosition(e) } }); dep.addEventListener("mouseleave", () => { info.classList.remove("active") }); - dep.addEventListener("mousemove", e => { - // info.style.transform = "translate3d(" + e.layerX + "px," + e.layerY + "px, 0)"; - if(currentDepGuessed == -1) { - info.style.top = `${e.pageY - 70}px`; - info.style.left = `${e.pageX - 0}px`; - } - }); + dep.addEventListener("mousemove", updatePosition); } } } |