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

interact.createSnapGrid from current position #204

Closed
razvanphp opened this issue Jun 13, 2015 · 5 comments
Closed

interact.createSnapGrid from current position #204

razvanphp opened this issue Jun 13, 2015 · 5 comments

Comments

@razvanphp
Copy link
Contributor

First of all, thank you for this great library, I will finally get rid of jQuery UI in my project.

After some struggle to port my draggable to interact.js, I found out a case that probably should be included in the lib core.

Since I have my own grid displayed on the page already, and the object is already positioned correctly, I want to snap relative to the current position of the item and the parent, and not the page itself.

Currently I solved it by providing an offset with $('object').parent().offset().top but this seems hacky.

jQuery UI has this assumed by default when you specify a grid. Also it accepts one coordinate to be 0, so that it snaps only in one direction. Hope you can provide this functionality too for easier learning curve.

Cheers!

@taye
Copy link
Owner

taye commented Jun 14, 2015

I can't be very sure of what you're doing without seeing a working demo, but the Interactable#origin setting might be what you need.

interact(target).origin('parent');

@razvanphp
Copy link
Contributor Author

Yes, this is what I mean, it works, but in my case I still have to add offset 1px because of the border.

What I wanted to say, is that the snap option should allow the possibility to build the grid (40x40 for example) starting from the current position of the item. Right now, it calculates and draws the grid starting from the origin top position.

To be more plastic, what I want to achieve is a 40x40 grid with the first move to be exactly 40 px up or down. Currently the first move is less, until the item position is synchronised with the actual grid, and the it moves fine.

I can create a fiddle if it is still not clear enough.

@max-mykhailenko
Copy link

Have same issue. @razvanphp do you solved that?

@razvanphp
Copy link
Contributor Author

Not really, @taye solution with origin breaks my other code, since event.dy returns some negative big values instead of multiple of grid size.

So current workaround is to use interact.createSnapGrid({offset: {x: 0, y: 175}}) and try to overlap the virtual grid with your wished movement steps.

@taye taye closed this as completed in 7f30da8 Nov 8, 2015
@taye
Copy link
Owner

taye commented Nov 8, 2015

I've made self an accepted value for snap offset. It works a lot like the startCoords value but uses the top-left of the target element at the start of the action instead of the pointer coordinates.

interact(target).draggable({
  snap: { offset: 'self', ... }
});

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

No branches or pull requests

3 participants