-
Notifications
You must be signed in to change notification settings - Fork 786
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
Restricting a drag with parent as origin. #1032
Comments
Have you tried using the restrictRect modifier?
|
I appreciate the example code @dylanzenner . However, the example you provide restricts the draggable element to the entire parent container. As stated in my initial post, I'm interested in trying to restrict the dragging to a sub-section of the parent, e.g. the top left 100x100 of a 200x200 parent container for at 50x50 draggable element. I have tried using the So far, I work-around the problem by re-calculating absolute view port co-ordinates and pass these to InteractJS via |
@Gazoo101 Are you able to add another div to the parent container that you can restrict the 50x50 div to? Here is a fiddle link: https://jsfiddle.net/5oLsnzcj/3/ basically what you could do is "nest" 3 containers to achieve this and if you need the 100x100 div to not interfere with other items on your page you could position it absolutely in the top left corner. This way you have a way to use If this still does not work for you let me know |
@dylanzenner I appreciate your on-going dialogue with me about this, and your patience. My paid work gives me a bit less time these days, so I bare with me if I don't answer for a bit. I also appreciate the example. In most cases I use a parent Div as this works exactly as you describe. In this particular instance, the elements I want to drag limit eachother. Imagine 3 boxes on a single axis, none of which can be dragged passed eachother, but limit eachothers positioning. If I used a parent div to restrict each of the 3 boxes, I'd instead be faced with the new problem of resizing these 3 parent divs. Hence why relative co-ordinates to restrict dragging would be the most straight-forward approach as far as I know. |
I'm trying to set a drag restriction with the origin of co-ordinates as the parent element, e.g. a 50x50 div inside of a 200x200 div, which can only move within a 100x100 area of the larger 200x200 div.
I've come across the
.origin()
function, but it doesn't appear to apply to the drag restriction I set. For example when I define:this ends up restricting the small 50x50 div to the top-left corner of the page instead. Anyone else had any luck with using relative co-ordinates for drag restrictions?
The text was updated successfully, but these errors were encountered: