fix tile unwanted movement, and offset

This commit is contained in:
Raphaël Jakse 2020-04-02 19:09:47 +02:00
parent 1b72bd789f
commit 7b516bf68c
1 changed files with 14 additions and 4 deletions

View File

@ -190,8 +190,8 @@
var newLeft = (tileInitCoords.left + (e.clientX - tileInitMouseCoords.clientX));
var newTop = (tileInitCoords.top + (e.clientY - tileInitMouseCoords.clientY));
movingTile.style.left = newLeft + "px";
movingTile.style.top = newTop + "px";
movingTile.style.left = (newLeft + window.scrollX) + "px";
movingTile.style.top = (newTop + window.scrollY) + "px";
var newDest = null;
@ -307,6 +307,7 @@
}
function dragTileBegin(e) {
e.preventDefault();
loadAudio();
if (blockMove) {
return;
@ -357,8 +358,8 @@
mouseMove(document, dragTileMove);
mouseUp(document, dragTileEnd);
movingTile.style.left = tileInitCoords.left + "px";
movingTile.style.top = tileInitCoords.top + "px";
movingTile.style.left = tileInitCoords.left + window.scrollX + "px";
movingTile.style.top = tileInitCoords.top + window.scrollY + "px";
movingTile.style.width = tileInitCoords.width + "px";
movingTile.style.height = tileInitCoords.height + "px";
@ -378,6 +379,11 @@
}
}
function preventDefault(e) {
e.preventDefault();
return false;
}
function makeLetter(letter, highlight) {
var tile = document.createElement("span");
tile.className = "tile";
@ -386,6 +392,10 @@
tile.appendChild(document.createElement("span"));
tile.lastChild.className = "tile-score";
mouseDown(tile, dragTileBegin);
tile.addEventListener("contextmenu", preventDefault);
tile.addEventListener("touchmove", preventDefault);
setLetter(tile, letter, highlight);
return tile;
}