Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Options Grid snap on dragEnd #65

Closed
ghost opened this issue Nov 9, 2014 · 7 comments
Closed

Options Grid snap on dragEnd #65

ghost opened this issue Nov 9, 2014 · 7 comments

Comments

@ghost
Copy link

ghost commented Nov 9, 2014

Hi man,

Is it possible to add/set the "grid" option on "dragEnd", so the object
is free to move outside of the "grid", and when you release it on "dragEnd"
it adapts and snaps into place (grid).

If you have a solution without digging around in core files or
maybe motivation to add a new option for this it would be seriously super duper amazing mega
awesome...

Best regards /
Monk

dragger = new Draggabilly(elem, {
       containment: true,
       grid: [ 0 , 0 ]
});

dragger.on('dragStart', function () {
       dragger.options.grid = [0, 0];
});

dragger.on('dragEnd', function () {
       dragger.options.grid = [100, 100];
});
@ghost ghost changed the title Options Grid Options Grid snap on dragEnd Nov 10, 2014
@desandro
Copy link
Owner

Interesting idea. Here's a hack that does it: http://codepen.io/desandro/pen/gbYELj

@ghost
Copy link
Author

ghost commented Nov 11, 2014

Yiiiiiiiiaaaaah now thats cool, thanks a lot man !
hmm trying to add some butter but it behaves rather strange and jumpy, any ideas?
http://codepen.io/anon/pen/wBwZrG?editors=001

@ghost
Copy link
Author

ghost commented Nov 11, 2014

hmm behaves crazy on webkit browsers and great on firefox.. hmm
webkitTransitionDuration does not seem to work either..

@desandro
Copy link
Owner

I'll leave that implementation up to you.

@ghost
Copy link
Author

ghost commented Nov 11, 2014

Well thank you sir.
Omg. no pressure, remember breathe..
One, two, three, breathe! One, two, three, breathe...

@desandro
Copy link
Owner

desandro commented Mar 8, 2015

I've updated the code so it's not munging with prototype.dragEnd. This code works with both Draggabilly v1.1.x and v1.2.x. http://codepen.io/desandro/pen/gbYELj

var draggie = new Draggabilly('.draggie');
var grid = [ 40, 40 ];

draggie.on( 'dragEnd', function() {
  draggie.position.x = applyGrid( draggie.position.x, grid[0] );
  draggie.position.y = applyGrid( draggie.position.y, grid[1] );
  draggie.setLeftTop();
});

or with jQuery

var $draggable = $('.draggie').draggabilly();
var draggie = $draggable.data('draggabilly');
var grid = [ 40, 40 ];

$draggable.on( 'dragEnd', function() {
  draggie.position.x = applyGrid( draggie.position.x, grid[0] );
  draggie.position.y = applyGrid( draggie.position.y, grid[1] );
  draggie.setLeftTop();
});

@ghost
Copy link
Author

ghost commented Mar 9, 2015

Aaahh cool man, looks great, thanks a lot !!

8 mar 2015 kl. 18:23 skrev David DeSandro notifications@github.com:

I've updated the code so it's not munging with prototype.dragEnd. This code works with both Draggabilly v1.1.x and v1.2.x. http://codepen.io/desandro/pen/gbYELj http://codepen.io/desandro/pen/gbYELj
var draggie = new Draggabilly('.draggie');
var grid = [ 40, 40 ];

draggie.on( 'dragEnd', function() {
draggie.position.x = applyGrid( draggie.position.x, grid[0] );
draggie.position.y = applyGrid( draggie.position.y, grid[1] );
draggie.setLeftTop();
});
or with jQuery

var $draggable = $('.draggie').draggabilly();
var draggie = $draggable.data('draggabilly');
var grid = [ 40, 40 ];

$draggable.on( 'dragEnd', function() {
draggie.position.x = applyGrid( draggie.position.x, grid[0] );
draggie.position.y = applyGrid( draggie.position.y, grid[1] );
draggie.setLeftTop();
});

Reply to this email directly or view it on GitHub #65 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant