I want to position a draggable div within the divs parents center. See example here
$("#mover").draggable({
revert: true,
containment: "parent"
});
<div style="width: 100px; height: 100px;" id="joystick">
<div style="width: 10px; height: 10px" id="mover"></div><br />
</div>
Now, it works fine, but as soon as I want to position the mover at the joysticks center, the dragging doesn’t work the way I want it to.
I tried positioning it giving the mover a margin: 45px 0 0 45px;, but then (because of the box-model seeing the margin as a part of the box) the dragging still only works down and right, and not up and left.
As you see, I want to create kind of a “joystick” used to steer something. Therefore, it needs to be centered but also be movable in all axis’.
Any ideas would be highly appreciated.
Here’s a full working demo, you have to position the center of the joystick with
position:relative;: http://jsfiddle.net/E6BQe/HTML:
CSS:
javascript: