From 6e9bb670c3d6c9e5ecf344faad4b9b31fa00ea19 Mon Sep 17 00:00:00 2001 From: yjf2002ghty <47345902+yjf2002ghty@users.noreply.github.com> Date: Sat, 14 Dec 2024 14:22:30 +0800 Subject: [PATCH] Fix mini board moving Signed-off-by: yjf2002ghty <47345902+yjf2002ghty@users.noreply.github.com> --- src/html/advanced.html | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/html/advanced.html b/src/html/advanced.html index 2c476525..c6f1db72 100644 --- a/src/html/advanced.html +++ b/src/html/advanced.html @@ -2606,6 +2606,9 @@ chessgroundmini.style.top = `${window.innerHeight - chessgroundminirect.height - padding}px`; } } else { + chessgroundmini.style.left = `${chessgroundminirect.left - maindivrect.left}px`; + chessgroundmini.style.top = `${chessgroundminirect.top - maindivrect.top}px`; + chessgroundmini.style.position = ""; if (chessgroundminirect.left < maindivrect.left + padding) { chessgroundmini.style.left = `${maindivrect.left + padding}px`; } else if (chessgroundminirect.right > maindivrect.right - padding) { @@ -2650,6 +2653,9 @@ chessgroundmini.style.top = `${window.innerHeight - chessgroundminirect.height - padding}px`; } } else { + chessgroundmini.style.left = `${chessgroundminirect.left - maindivrect.left}px`; + chessgroundmini.style.top = `${chessgroundminirect.top - maindivrect.top}px`; + chessgroundmini.style.position = ""; if (chessgroundminirect.left < maindivrect.left + padding) { chessgroundmini.style.left = `${maindivrect.left + padding}px`; } else if (chessgroundminirect.right > maindivrect.right - padding) { @@ -2684,15 +2690,14 @@ ) { return; } - const maindivrect = maindiv.getBoundingClientRect(); const chessgroundminirect = chessgroundmini.getBoundingClientRect(); - if (chessgroundmini.pinned) { - startX = chessgroundminirect.left; - startY = chessgroundminirect.top; - } else { - startX = chessgroundminirect.left - maindivrect.left; - startY = chessgroundminirect.top - maindivrect.top; + if (!chessgroundmini.pinned) { + chessgroundmini.style.left = `${chessgroundminirect.left}px`; + chessgroundmini.style.top = `${chessgroundminirect.top}px`; + chessgroundmini.style.position = "fixed"; } + startX = chessgroundminirect.left; + startY = chessgroundminirect.top; initialX = event.clientX; initialY = event.clientY; document.addEventListener("mousemove", onMouseMove); @@ -2705,13 +2710,14 @@ if (event.touches && event.touches.length > 1) { return; } - if (chessgroundmini.pinned) { - return; - } - const maindivrect = maindiv.getBoundingClientRect(); const chessgroundminirect = chessgroundmini.getBoundingClientRect(); - startX = chessgroundminirect.left - maindivrect.left; - startY = chessgroundminirect.top - maindivrect.top; + if (!chessgroundmini.pinned) { + chessgroundmini.style.left = `${chessgroundminirect.left}px`; + chessgroundmini.style.top = `${chessgroundminirect.top}px`; + chessgroundmini.style.position = "fixed"; + } + startX = chessgroundminirect.left; + startY = chessgroundminirect.top; initialX = event.touches[0].clientX; initialY = event.touches[0].clientY; document.addEventListener("touchmove", onTouchMove);