diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2020-07-13 01:12:32 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2020-07-13 01:12:32 +0200 |
commit | 72922d2644a8f8150d5e0453c646b473625208b7 (patch) | |
tree | 543d0aad15da81d1b7a937c762e2200a18c2b9b8 /static/script.js | |
parent | Add basic movement of popups. (diff) | |
download | calp-72922d2644a8f8150d5e0453c646b473625208b7.tar.gz calp-72922d2644a8f8150d5e0453c646b473625208b7.tar.xz |
Fix popup movement.
Diffstat (limited to 'static/script.js')
-rw-r--r-- | static/script.js | 17 |
1 files 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")) { |