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

Constraint usage #24

Open
Santhoshsvg opened this issue Sep 8, 2016 · 3 comments
Open

Constraint usage #24

Santhoshsvg opened this issue Sep 8, 2016 · 3 comments

Comments

@Santhoshsvg
Copy link

Santhoshsvg commented Sep 8, 2016

Dear Ulrich,

I have a parent SVG element and lot of child elements which are having both draggable and resizable options attached to them.

When i try to drag or resize, i would like to do it within an constraint(within the parent SVG element boundary).

var containmentX1 = $("#cvs").offset().left;
var containmentY1 = $("#cvs").offset().top;
var containmentX2 = ($("#cvs").outerWidth()  +  $("#cvs").offset().left - $("#ChildElement").outerWidth());
var containmentY2 = ($("#cvs").outerHeight() +  $("#cvs").offset().top  - $("#ChildElement").outerHeight());
var opt = {
  constraint: {
    minX: 0,
    minY: 0,
    maxX: 1000,
    maxY: 1000
  }
};
this.resize(opt).draggable(opt);

But i couldnt achieve what i am supposed to do, the child elements can be dragged outside the parent element boundary .

Pls advice what needs to be done on this and the miss that i made in my implementation.

Thanks in advance.

@Fuzzyma
Copy link
Member

Fuzzyma commented Sep 12, 2016

The draggable-plugin does not has an option param but only a constraint param. So in your case obj should be replaced with obj.constraint leading to this code:

this.resize(opt).draggable(opt.constraint);

@Santhoshsvg
Copy link
Author

Hi Ulrich,

Is there any way for to pass both constraint as well snaptogrid for the draggable plugin.

Thanks in advance

@Fuzzyma
Copy link
Member

Fuzzyma commented Sep 13, 2016

There is no snapToGrid option in svg.draggable.js. You have to implement one on your own using the constraint feature. You can pass a function to constraint which is used to return the new x and y coordinates. See here on how to implement that: svgdotjs/svg.draggable.js#60

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

2 participants