Last active
January 5, 2021 05:21
-
-
Save theevilhead/7ac2fbc3cda897ebd87dbe9aeac130d6 to your computer and use it in GitHub Desktop.
Easiest way to detect direction of drag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var dragStartX; | |
var dragStartY; | |
window.addEventListener("dragstart",function(e){ | |
dragStartX = Math.ceil(e.offsetX/70); | |
dragStartY = Math.ceil(e.offsetY/70); | |
}) | |
window.addEventListener("dragend",function(e){ | |
var dropX = Math.abs(dragstartX - e.screenX); | |
var dropY = Math.abs(dragstartY - e.screenY); | |
if(dropX > dropY){ | |
// Direction is X | |
}else if(dropX < dropY){ | |
// direction is Y; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment