desandro / draggabilly

:point_down: Make that shiz draggable
https://draggabilly.desandro.com
MIT License
3.86k stars 386 forks source link

Add dragGridMove event #85

Closed walter-schwarz closed 8 years ago

walter-schwarz commented 9 years ago

Hello. Could you add a "dragStep" event that is similar to the dragMove event but only fires when the element is actually moved based on the defined grid. If no grid is defined it would behave just like dragMove. Thanks for the great work!

desandro commented 9 years ago

Interesting request! You can duck-punch a solution with this code:

var dragMove = Draggabilly.prototype.dragMove
Draggabilly.prototype.dragMove = function( event, pointer, moveVector ) {
  // do normal logic
  dragMove.apply( this, arguments );
  this.previousDragPoint = this.previousDragPoint || {};
  if ( this.dragPoint.x != this.previousDragPoint.x ||
    this.dragPoint.y != this.previousDragPoint.y ) {
    this.dispatchEvent( 'dragGridMove', event, [ pointer, moveVector ] );
  }
  this.previousDragPoint.x = this.dragPoint.x;
  this.previousDragPoint.y = this.dragPoint.y;
};

See demo: http://codepen.io/desandro/pen/waMwEp


+1 this issue if you would like to see dragGridMove event added to Draggabilly.

walter-schwarz commented 9 years ago

Thank you for the fast reply. It works great.

  _______ _                 _                        _ 
 |__   __| |               | |                      | |
    | |  | |__   __ _ _ __ | | __  _   _  ___  _   _| |
    | |  | '_ \ / _` | '_ \| |/ / | | | |/ _ \| | | | |
    | |  | | | | (_| | | | |   <  | |_| | (_) | |_| |_|
    |_|  |_| |_|\__,_|_| |_|_|\_\  \__, |\___/ \__,_(_)
                                    __/ |              
                                   |___/               
desandro commented 8 years ago

Looks like this feature didn't outside interest. Closing for now :strawberry: