Click here to Skip to main content
15,885,856 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Team,

I want to set drag limit of canvas object so it not
move outside of clip area.Here my clip area is shape
so please help me.






Thanks & Regards,
Rajeev Rahi

What I have tried:

canvas.on ("object:moving", function (event) {
var el = event.target;

// suppose el coords is center based

el.left = el.left < el.getBoundingRectWidth() / 2 ? el.getBoundingRectWidth() / 2 : el.left;
el.top = el.top < el.getBoundingRectHeight () / 2 ? el.getBoundingRectHeight() / 2 : el.top;

var right = el.left + el.getBoundingRectWidth() / 2;
var bottom = el.top + el.getBoundingRectHeight() / 2;

el.left = right > canvas.width - el.getBoundingRectWidth() / 2 ? canvas.width - el.getBoundingRectWidth() / 2 : el.left;
el.top = bottom > canvas.height - el.getBoundingRectHeight() / 2 ? canvas.height - el.getBoundingRectHeight() / 2 : el.top;
});

But work in rectangel case
Posted
Updated 3-Apr-16 21:39pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900