Matej Posted February 14, 2015 Share Posted February 14, 2015 Hi im building something like draggable map(using imag for this example) here http://jsfiddle.net/Trolstover/seqpj89L/1/. But i just cant figure out how to build something like "movement restriction" , so it wont move so much that i will see background of parent element (if you know what i mean) Any ideas? thanks for answers Link to comment Share on other sites More sharing options...
Ingolme Posted February 14, 2015 Share Posted February 14, 2015 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 More sharing options...
Matej Posted February 14, 2015 Author Share Posted February 14, 2015 Oh yea silly me ) , got it thanks Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now