Skip to content

Instantly share code, notes, and snippets.

@theevilhead
Last active January 5, 2021 05:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theevilhead/7ac2fbc3cda897ebd87dbe9aeac130d6 to your computer and use it in GitHub Desktop.
Save theevilhead/7ac2fbc3cda897ebd87dbe9aeac130d6 to your computer and use it in GitHub Desktop.
Easiest way to detect direction of drag
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