From 72922d2644a8f8150d5e0453c646b473625208b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 13 Jul 2020 01:12:32 +0200 Subject: Fix popup movement. --- static/script.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/static/script.js b/static/script.js index af0fba8f..8a314bb9 100644 --- a/static/script.js +++ b/static/script.js @@ -329,21 +329,24 @@ window.onload = function () { if (e.target != nav) return; nav.style.cursor = "grabbing"; nav.dataset.grabbed = "true"; - nav.dataset.grabPoint = e.layerX + ";" + e.layerY; + nav.dataset.grabPoint = e.clientX + ";" + e.clientY; + let popup = nav.closest(".popup-container"); + nav.dataset.startPoint = popup.offsetLeft + ";" + popup.offsetTop; } - nav.onmousemove = function (e) { + window.addEventListener('mousemove', function (e) { if (nav.dataset.grabbed) { let [x, y] = nav.dataset.grabPoint.split(";").map(Number); + let [startX, startY] = nav.dataset.startPoint.split(";").map(Number); let popup = nav.closest(".popup-container"); - popup.style.left = popup.offsetLeft + (e.layerX - x) + "px"; - popup.style.top = popup.offsetTop + (e.layerY - y) + "px"; + popup.style.left = startX + (e.clientX - x) + "px"; + popup.style.top = startY + (e.clientY - y) + "px"; } - } - nav.onmouseup = function () { + }); + window.addEventListener('mouseup', function () { nav.dataset.grabbed = ""; nav.style.cursor = ""; - } + }); } for (let el of document.getElementsByClassName("event")) { -- cgit v1.2.3