Jump to content

drag restriction


Matej

Recommended Posts

Your jsfiddle example isn't doing anything so I can't test your code.

 

If you want to prevent it from going further than a particular point, then in the drag event handler have an if() statement that compares the position of the object to the limits you don't want it to pass. You should know how to get the position of the element. The Max and min limits depend on the width and height of the parent element, the minimum limits are probably just zero.

if(xPosition > xMaxLimit) xPosition = xMaxLimit;if(xPosition < xMinLimit) xPosition = xMinLimit;if(yPosition > yMaxLimit) yPosition = yMaxLimit;if(yPosition < yMinLimit) yPosition = yMinLimit;
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...