metafizzy / packery

:bento: Gapless, draggable grid layouts
https://packery.metafizzy.co
4.14k stars 315 forks source link

Distinguish between drag and click events #482

Closed drinkwater99 closed 6 years ago

drinkwater99 commented 6 years ago

I am using dragging with jQuery UI Draggable.

How can I distinguish between a click or a drag ? That is, when I click on a grid item I want to show an alert() box but not when dragging a grid item. Is there some way to do this ?

frank-dspeed commented 6 years ago

@drinkwater99 you need to handle that in the click event handler there you need to track mouse up event if its still down then your dragging simply then track if mouse moves while down and then finaly if all that not happens fire your alert on mouse up

desandro commented 6 years ago

Or you can switch to Draggabilly and use its staticClick event.

See also solutions for jQuery UI draggable from this thread

drinkwater99 commented 6 years ago

In case anyone else falls on to this, here is the solution

$(".element") .draggable() .click(function(){ if ( $(this).is('.ui-draggable-dragging') ) { return; } // click action here });

frank-dspeed commented 6 years ago

@drinkwater99

$(".element")
.draggable()
.click(function(){
  if ( $(this).is('.ui-draggable-dragging') ) {
   return;
  }
// click action here
});