I am currently working on creating a draggable map. I have successfully limited the draggable child for the left and top sides, but I am struggling to do the same for the right and bottom sides.
How can I restrict the movement of a draggable child based on the right and bottom values of its parent element?
var uright = ui.position.left + 960; /* 960 represents the height of the map */
var pright = parentPos.left + 700; /* 500 is the height of the container */
if (ui.position.top > parentPos.top) {
ui.position.top = parentPos.top; // this works correctly
}
if (ui.position.left > parentPos.left) {
ui.position.left= parentPos.left; // this works correctly
}
if (uright > pright) {
uright = pright; // however, this part is not functioning as intended
}
For reference, here is my working example on jsfiddle