From 175c273d62c114ae4851cddc7f52a969def51a39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Macio=C5=82ek?= Date: Sat, 16 Sep 2023 20:49:59 +0200 Subject: [PATCH] drag center fix --- src/components/board/Pieces.vue | 7 ++++--- src/views/Game.vue | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/components/board/Pieces.vue b/src/components/board/Pieces.vue index 89cd6e7..2fb936a 100644 --- a/src/components/board/Pieces.vue +++ b/src/components/board/Pieces.vue @@ -56,7 +56,7 @@ function move(e: MouseEvent) { if (props.board == null) return; if (draggedElement.value == null) return; - var board = props.board.getBoundingClientRect(); + let board = props.board.getBoundingClientRect(); if ( e.clientX > board.left && @@ -64,9 +64,10 @@ function move(e: MouseEvent) { e.clientY > board.top && e.clientY < board.bottom ) { + let pieceSize = draggedElement.value.getBoundingClientRect().width / 2; draggedElement.value.style.transform = `translate(${ - e.clientX - board.left - 75 + window.scrollX + "px" // 50 is half of the piece size (100px) - }, ${e.clientY - board.top - 75 + window.scrollY + "px"})`; + e.clientX - board.left - pieceSize + window.scrollX + "px" + }, ${e.clientY - board.top - pieceSize + window.scrollY + "px"})`; } } diff --git a/src/views/Game.vue b/src/views/Game.vue index 8a72c3e..c864aca 100644 --- a/src/views/Game.vue +++ b/src/views/Game.vue @@ -74,13 +74,13 @@ function tryMove(e: MouseEvent) { REPO Report bug