Skip to content

Commit

Permalink
Try preventing overlap in dragging
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkosiikaniemi committed Oct 7, 2023
1 parent a5aa02a commit 9dc25f0
Showing 1 changed file with 20 additions and 26 deletions.
46 changes: 20 additions & 26 deletions touchsprint.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@ finger2.addEventListener("touchstart", startDrag2);
document.addEventListener("mousemove", drag);
document.addEventListener("touchmove", drag);

document.addEventListener("mouseup", endDrag);
document.addEventListener("touchend", endDrag);
//document.addEventListener("mouseup", endDrag);
finger1.addEventListener("touchend", endDrag1);
finger2.addEventListener("touchend", endDrag2);

document.addEventListener('touchmove', function (event) {
if (event.scale !== 1) { event.preventDefault(); }
}, { passive: false });

function startDrag1(e) {
console.log('Dragging 1.')
isDragging1 = true;
endDrag2();

// Handle both mouse and touch events
if (e.type === "mousedown") {
Expand All @@ -59,6 +60,7 @@ function startDrag1(e) {

function startDrag2(e) {
isDragging2 = true;
endDrag1();

// Handle both mouse and touch events
if (e.type === "mousedown") {
Expand Down Expand Up @@ -143,33 +145,25 @@ function drag(e) {
body.style.backgroundPositionY = totalDistance + "px";

distanceDisplay.textContent = totalDistance.toFixed(0);

// Update the initial position for the next drag


}
}

function endDrag() {
if (isDragging1) {

// Reset the element's position to "absolute" and return it to its original place
finger1.style.position = "absolute";
finger1.style.zIndex = "0";
finger1.style.left = originalPositionX1;
finger1.style.top = originalPositionY1;
function endDrag1() {
// Reset the element's position to "absolute" and return it to its original place
finger1.style.position = "absolute";
finger1.style.zIndex = "0";
finger1.style.left = originalPositionX1;
finger1.style.top = originalPositionY1;

isDragging1 = false;
}

if (isDragging2) {
isDragging1 = false;
}

// Reset the element's position to "absolute" and return it to its original place
finger2.style.position = "absolute";
finger2.style.zIndex = "0";
finger2.style.left = originalPositionX2;
finger2.style.top = originalPositionY2;
function endDrag2() {
// Reset the element's position to "absolute" and return it to its original place
finger2.style.position = "absolute";
finger2.style.zIndex = "0";
finger2.style.left = originalPositionX2;
finger2.style.top = originalPositionY2;

isDragging2 = false;
}
isDragging2 = false;
}

0 comments on commit 9dc25f0

Please sign in to comment.